I found what made problem for 'nullPointerException'(Request processing failed; nested exception is 'java.lang.NullPointerException') as I used object 'ModelAndView' in the controller below.
Three kinds of variables can't get null below.
I know variable 'viewName' in the controller can't get value and object Map also can bring clear value as well. Furthermore, the variable 'idto' of object 'ItemDTO' has null instead of any value.
How can I fix existing codes suitable for the variables to get right value?
Below is the codes relevant to what I explain.
The code is controller below.
#Controller
#RequestMapping("booksale")
public class BookSaleController {
#Inject
private BookSaleService bService;
#RequestMapping(value="/itemDetail/{ino}")
public ModelAndView itemDetail(#PathVariable("ino")int ino, HttpServletRequest request,
HttpServletResponse response) {
String viewName = (String) request.getAttribute("viewName");
HttpSession session = request.getSession();
Map iMap = bService.itemDetail(ino);
ModelAndView mav = new ModelAndView(viewName);
mav.setViewName("/itemDetail/{ino}");
mav.addObject("iMap", iMap);
ItemDTO idto = (ItemDTO) iMap.get("idto");
appendItemQmenu(ino, idto, session);
return mav;
}
private void appendItemQmenu(int ino, ItemDTO idto, HttpSession session) {
// TODO Auto-generated method stub
boolean existing_presence = false;
List<ItemDTO> QuickItemList =
(List<ItemDTO>) session.getAttribute("QuickItemList");
if (QuickItemList != null) {
if (QuickItemList.size() < 3) {
for (int i = 0; i < QuickItemList.size(); i++) {
ItemDTO itemBean = QuickItemList.get(i);
String sIno = Integer.toString(ino);
if (sIno.equals(itemBean.getIno())) {
existing_presence = true;
return;
}
}
if (existing_presence== false) {
QuickItemList.add(idto);
}
}
}else {
QuickItemList = new ArrayList<ItemDTO>();
QuickItemList.add(idto);
}
session.setAttribute("QuickItemList", QuickItemList);
session.setAttribute("QuickItemListNum", QuickItemList.size());
}
The second code is about servlet-context.xml which is linked to MyBatis below.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC #Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by #Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</beans:bean>
<context:component-scan base-package="com.bookshop01" />
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/*/*.do"/>
<mvc:mapping path="/*/*/*.do"/>
<beans:bean class="com.bookshop01.common.interceptor.ViewNameInterceptor" />
</mvc:interceptor>
</mvc:interceptors>
<!-- MultiPartResolver -->
<beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<beans:property name="maxUploadSize" value="52428800" />
<beans:property name="maxInMemorySize" value="52428800" />
<beans:property name="defaultEncoding" value="utf-8" />
</beans:bean>
</beans:beans>
Final code is about itemDetail.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%# taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<c:set var="items" value="${itemMap.iDTO}"/>
<c:set var="imageList" value="${itemMap.imageList}"/>
<%
pageContext.setAttribute("crcn", "\n");
pageContext.setAttribute("br", "<br/>");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<title>Insert title here</title>
<style>
#layer {
z-index: 2;
position: absolute;
top: 0px;
left: 0px;
width: 100%;
}
#popup {
z-index: 3;
position: fixed;
text-align: center;
left: 50%;
top: 45%;
width: 300px;
height: 200px;
background-color: #ccffff;
border: 3px solid #87cb42;
}
#close {
z-index: 4;
float: right;
}
.modal{
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%) scale(0);
transition: 200ms ease-in-out;
border: 1px solid black;
border-radius: 10px;
z-index: 10;
background-color: white;
width: 500px;
max-width: 80%;
}
.modal .active{
transform: translate(-50%, -50%) scale(1);
}
.modal-header{
padding: 10px 15px;
display: flex;
justify-content: space-between;
align-items: center;
border-bottom: 1px solid black;
}
.modal-header .title{
font-size: 1.25rem;
font-weight: bold;
}
.modal-header .close-button{
cursor: pointer;
border: none;
outline: none;
background: none;
font-size: 1.25rem;
font-weight: bold;
}
.modal-body{
padding: 10px 15px;
}
#overlay {
position: fixed;
opacity: 0;
transition: 200ms ease-in-out;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0,0,0,.5);
pointer-events: none;
}
#overlay .active{
opacity: 1;
pointer-events: all;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
function add_cart(ino){
$.ajax({
type: "post",
async: false,
url: ${contextPath}/
data: {
ino:ino
},
success : function(data, textStatus){
if(data.trim()=='add success'){
openModal(modal);
}else if(data.trim()=='existing_presence'){
alert("Already choosen");
}
},
error : function(data, textStatus){
alert("Error occured"+data);
}
});
}
var openModalButtons = document.querySelectorAll('[data-modal-target]');
var closeModalButtons = document.querySelectorAll('[data-close-button]');
var overlay = document.getElementById('overlay');
openModalButtons.forEach(button =>){
button.addEventListener('click', () =>){
var modal = document.querySelector(button.dataset.modalTarget)
openModal(modal);
})
})
overlay.addEventListener('click', () => {
var modals = document.querySelectorAll('.modal.active')
modals.forEach(modal => {
closeModal(modal)
})
})
closeModalButtons.forEach(button =>){
button.addEventListener('click', () =>){
var modal = button.closest('.modal')
closeModal(modal);
})
})
function openModal(modal){
if(modal == null) return
modal.classList.add('active')
overlay.classList.add('active')
}
function closeModal(modal){
if(modal == null) return
modal.classList.remove('active')
overlay.classList.remove('active')
}
function fn_pickup_items(ino, ititle, price, filename){
var LogOn = document.getElementById("LogOn");
var isLogOn = LogOn.value;
if(isLogOn == "false" || isLogOn == ''){
alert("You can order if you sign in")
}
var total_price, final_total_price;
var pcs = document.getElementById("pcs");
var form = document.createElement("form");
var i_ino = document.createElement("input");
var i_ititle = document.createElement("input");
var i_sales_price = document.createElement("input");
var i_filename = document.createElement("input");
var i_pcs = document.createElement("input");
i_ino.name = "ino";
i_ititle.name = "ititle";
i_sales_price.name = "sales_price";
i_filename.name = "filename";
i_pcs.name = "pcs";
i_ino.value = ino;
i_ititle.value = ititle;
i_sales_price.value = sales_price;
i_filename.value = filename;
i_pcs.value = pcs;
form.appendChild(ino);
form.appendChild(ititle);
form.appendChild(sales_price);
form.appendChild(filename);
form.appendChild(pcs);
document.body.appendChild(form);
form.method="post";
form.action="${contextPath}/pickup/pickupinsert.jsp";
form.submit();
}
});
</script>
</head>
<body>
<%# include file="../detailview/header.jsp" %>
<%# include file="../detailview/navbar.jsp" %>
<div class="container">
<div class="row">
<div class="col-sm-4">
<div class="bookimg">
<img alt="" src="/resources/img/book.jpg">
</div>
<div class="stock">
<label for="stock">Stock</label>
<p>{dto.stock}</p>
</div>
</div>
<div class="col-sm-8">
<div id="detail_table">
<table>
<tbody>
<tr>
<td class="fixed">Net price</td>
<td class="active"><span>
<fmt:formatNumber value="${dto.price}" type="number" var="price" />
${price}
</span></td>
</tr>
<tr class="dot_line">
<td class="fixed">Selling price</td>
<td class="active"><span>
<fmt:formatNumber value="${dto.price*0.9}" type="number" var="discounted_price"/>
${discounted_price}(10% discount)</span></td>
</tr>
<tr>
<td class="fixed">Gathering Points</td>
<td class="active">${dto.point}P(10% mileage)</td>
</tr>
<tr class="dot_line">
<td class="fixed"> Additional mileage of points</td>
<td class="fixed">Getting 1,000 points if purcahsing more than 10,000 won,
2,000 points if purchasing 50,000 won or additional mileage 300 points in using delivery service of convenient store</td>
</tr>
<tr>
<td class="fixed">published date</td>
<td class="fixed">
<c:set var="pub_date" value="${dto.publishDay}" />
<c:set var="arr" value="${fn:split(pub_date,' ')}" />
<c:out value="${arr[0]}" />
</td>
</tr>
<tr>
<td class="fixed">Total page</td>
<td class="fixed">${dto.totalPage}page</td>
</tr>
<tr>
<td class="fixed">Delivery fare</td>
<td class="fixed"><strong>Free of charge</strong></td>
</tr>
<tr>
<td class="fixed">Guide to deliver</td>
<td class="fixed"><strong>[One-day delivery]</strong> Start one-day delivery!<br> <strong>[Delivery for weekends]</strong>
Able to deliver for weekends</TD>
</tr>
<tr>
<td class="fixed">date to arrive</td>
<td class="fixed">Able to get next day if you order in the morning</td>
</tr>
<tr>
<td class="fixed">
<button id="pcs" type="button">Quantity</button>
</td>
</tr>
</tbody>
</table>
<ul>
<li><a class="buy" href="javascript:fn_pickup_items('${dto.ino}','${dto.ititle}','${dto.sales_price}','${dto.filename}');">Purchase </a></li>
<li><a class="cart" href="javascript:add_cart('${dto.ino}')">Cart</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="container">
<ul class="nav nav-tabs">
<li class="active">Classification on book</li>
<li>information on book</li>
<li>Table of contents & Contents</li>
<li>Information on writer</li>
<li>Introduction by writer</li>
</ul>
<div class="tab_container">
<div class="tab_content" id="t1">
<h4>Classification on book</h4>
<p>${fn:replace(dto.classify,crcn,br)}</p>
<c:forEach var="img" items="${imageList}">
<img src="${contextPath}/.?">
</c:forEach>
</div>
</div>
<div class="tab_content" id="t2">
<h4>Information on book</h4>
<p>${fn:replace(dto.prolog,crcn,br)}</p>
</div>
<div class="tab_content" id="t3">
<h4>Table of contents & Contents</h4>
<div class="Table_of_Content">Table of contents</div>
<p>${fn:replace(dto.TC,crcn,br)}</p>
<div class="contents">Contents</div>
<p>${fn:replace(dto.contents,crcn,br)}</p>
</div>
<div class="tab_content" id="t4">
<h4>Information on writer</h4>
<p>${fn:replace(dto.iwriter,crcn,br)}</p>
<p>${fn:replace(dto.iwri_pro,crcn,br)}</p>
</div>
<div class="tab_content" id="t5">
<form name="form" method="post" action="#">
<input type="hidden" name="membno" id="membno">
<input type="hidden" name="bookcd" id="bookcd" value="100993608">
<input type="hidden" name="device" value="p">
<input type="hidden" name="actionType" id="rev_ins_type">
<input type="hidden" name="review_no" id="rev_ins_no">
<input type="hidden" name="valuation" id="rev_ins_rate">
<div class="writeArea">
<h3 id="noView">You can be capable of leaving your feeling as reader if you sign in.</h3>
<img src="#" alt="You can be capable of leaving your feeling as reader if you sign in.">
<dl>
<dt>Grades on book</dt>
<dd>
<input type="radio" value="1" name="radio_revRate" class="writeRadio">
<img src="/resources/img/star.png">
<input type="radio" value="2" name="radio_revRate" class="writeRadio">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<input type="radio" value="3" name="radio_revRate" class="writeRadio">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<input type="radio" value="4" name="radio_revRate" class="writeRadio">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<input type="radio" value="4" name="radio_revRate" class="writeRadio">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
<img src="/resources/img/star.png">
</dd>
<dt>Contents</dt>
<dd>
<textarea name="review_content" id="review_content" class="writeText"
style="height:47px;" onclick="review_popup('login');"
onkeyup="fc_chk_byte(this, 4000);checkByteLength($(this).val(), 'review_content', 'tcount');"
hname="contents" required></textarea>
<a href="javascript:review popup('login');"
class="mL10 reg-btn">Registration</a>
</dd>
<dd id="tcount">0/2000(Max 2000 letters)</dd>
</dl>
</div>
</form>
</div>
</div>
<div class="clear"></div>
<button data-modal-target="#modal"></button>
<div class="modal" id="modal">
<div class="modal-header">
<div class="title"></div>
<button data-close-button class="close-button">×</button>
</div>
<div class="modal-body">
</div>
</div>
<div class="active" id="overlay"></div>
</body>
</html>
From your question I understand that the value returned from the map in the line is null.
ItemDTO idto = (ItemDTO) iMap.get("idto");
You are seeing this error because the Map does not contain an entry corresponding to the key 'idto'. Please check if the values is supposed to be present in the map, if the entry is to be present then why the entry is missing.
Other thing that you can do in the same line
ItemDTO idto = (ItemDTO) iMap.getOrDefault("idto", "DefaultValue");
This will try to find the entry corresponding to the key 'idto', if the entry is absent then it returns a default value 'DefaultValue'.
You can check this for more details https://docs.oracle.com/javase/8/docs/api/java/util/Map.html#getOrDefault-java.lang.Object-V-
Related
Main class:
package com.example.handlingformsubmission;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
public class HandlingFormSubmissionApplication {
public static void main(String[] args) {
SpringApplication.run(HandlingFormSubmissionApplication.class, args);
}
}
Controller:(here in Post mapping something wrong with code which is supposed to pass values of variable to another page, but it doesn't):
package com.example.handlingformsubmission;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
#Controller
public class GreetingController {
#GetMapping("/z.html")
public String greetingForm(Model model) {
model.addAttribute("z.html", new Greeting());
return "z.html";
}
#GetMapping("/zu.html")
public String greetingForm2(Model model) {
model.addAttribute("zu.html", new Greeting());
return "zu.html";
}
#GetMapping("/zus.html")
public String greetingForm3(Model model) {
model.addAttribute("zus.html", new Greeting());
return "zus.html";
}
#GetMapping("/zusu.html")
public String greetingForm4(Model model) {
model.addAttribute("zusu.html", new Greeting());
return "zusu.html";
}
#PostMapping("/zusu_generated.html")
public String greetingSubmit(#ModelAttribute Greeting greeting, Model model) {
model.addAttribute("zusu_generated.html",greeting);
model.addAttribute("Unit", greeting.getUnit());
model.addAttribute("Restarttype", greeting.getRestarttype());
return "zusu_generated.html";
}
}
Class where variables are declared (and getters and setters are configured):
package com.example.handlingformsubmission;
public class Greeting {
public String Restarttype;
public String Unit;
public String getRestarttype() {
return Restarttype;
}
public void setRestarttype(String Restarttype) {
this.Restarttype = Restarttype;
}
public String getUnit() {
return Unit;
}
public void setUNIT(String Unit) {
this.Unit = Unit;
}
}
HTML web page where web form accepts values of variable:
<!DOCTYPE HTML>
<html xmlns:th="https://www.thymeleaf.org" xmlns:form="http://www.w3.org/1999/xhtml">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css.css" />
<style type="text/css">
.block1 {
width: 20px;
background: #ffffff;
padding: 5px;
padding-right: 20px;
border: solid 1px white;
float: left;
margin-top: 17%; /* Отступ сверху */
}
.block2 {
width: 1360px;
background: #ffffff;
padding: 5px;
padding-right: 20px;
border: solid 1px black;
float: left;
margin-top: 17%; /* Отступ сверху */
text-align:center;
}
.block3 {
width: 20px;
background: #ffffff;
padding: 5px;
padding-right: 20px;
border: solid 1px white;
float: left;
margin-top: 17%; /* Отступ сверху */
}
a.hover: underline(none)
</style>
</head>
<body>
<div class="row">
<div class="block1"></div>
<div class="block2">
<h1>Nokia BSC3i ZUSU command</h1>
<form action="#" th:action="#{/zusu_generated.html}" th:object="${greeting}" method="post">
<table align = center>
<tr>
<td> ZUSU:</td>
<td>
<label for="Unit">Unit:</label>
<select name="Unit" id="Unit">
<optgroup label="Unit">
<option value="BCSU">BCSU</option>
<option value="Clock">Clock</option>
<option value="ET">ET</option>
</optgroup>
</select>
</td>
<td>
C
</td>
<td> = </td>
<td>
<label for="Restart value"> </label>
<select name="Restart type" id="Restart value">
<optgroup label="Restart type">
<option value="TOT">TOT</option>
<option value="HALF">HALF</option>
<option value="PARTIAL">PARTIAL</option>
</optgroup>
</select>
</td>
</tr>
</table>
<p><input type="submit" value="Generate command" /> <input type="reset" value="Reset"
/></p>
</form>
</div>
<div class="block3"></div>
</div>
</body>
</html>
HTML web page where variable values should appear, but they don't appear:
<!DOCTYPE HTML>
<html xmlns:th="https://www.thymeleaf.org" xmlns:form="http://www.w3.org/1999/xhtml">
<head>
<title>Getting Started: Handling Form Submission</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="css.css" />
<style type="text/css">
.block1 {
width: 20px;
background: #ffffff;
padding: 5px;
padding-right: 20px;
border: solid 1px white;
float: left;
margin-top: 17%; /* Отступ сверху */
}
.block2 {
width: 1360px;
background: #ffffff;
padding: 5px;
padding-right: 20px;
border: solid 1px black;
float: left;
margin-top: 17%; /* Отступ сверху */
text-align:center;
}
.block3 {
width: 20px;
background: #ffffff;
padding: 5px;
padding-right: 20px;
border: solid 1px white;
float: left;
margin-top: 17%; /* Отступ сверху */
}
a.hover: underline(none)
</style>
</head>
<body>
<div class="row">
<div class="block1"></div>
<div class="block2">
<h1>Nokia BSC3i ZUSU command</h1>
<form action="#" th:action="#{/greeting}" th:object="${greeting}" method="post">
<table align = center>
<tr>
<td>ZUSU:</td>
<td>
<label for="Unit">Unit:</label>
<select name="Unit" id="Unit">
<optgroup label="Unit">
<option value="BCSU">BCSU</option>
<option value="Clock">Clock</option>
<option value="ET">ET</option>
</optgroup>
</select>
</td>
<td>
C
</td>
<td> = </td>
<td>
<label for="Restart value"> </label>
<select name="Restart type" id="Restart value">
<optgroup label="Restart type">
<option value="TOT">TOT</option>
<option value="HALF">HALF</option>
<option value="PARTIAL">PARTIAL</option>
</optgroup>
</select>
</td>
</tr>
<tr>
<td>
<p th:text="'Generated command is: ZUSU: UNIT = ' + ${greeting.Unit} + ' C = ' + ${greeting.Restarttype}" />
</td>
</tr>
</table>
<p><input type="submit" value="Copy to memory" /> <input type="reset" value="Reset" />
</p>
</form>
</div>
<div class="block3"></div>
</div>
</body>
</html>
A have simple CRUD web application. And I want to bind UI and backend with thymeleaf. After I create some data and get server response - all styles are disappearing. I'm new to thymeleaf, CSS and HTML. Can someone help me to figure out where is the problem?
Before and after:
Save operation method:
#PostMapping("/user/save")
public ModelAndView save(#ModelAttribute("userDTO") #Valid UserDTO userDTO,
BindingResult bindingResult, WebRequest request, Errors errors) {
User registered = new User();
if (!bindingResult.hasErrors()) {
registered = createUserAccount(userDTO, bindingResult);
}
if (registered == null) {
bindingResult.rejectValue("email", "message.regError");
}
if (bindingResult.hasErrors()) {
bindingResult.getAllErrors().forEach(error -> log.error(error.toString()));
return new ModelAndView("authorization/registration", "error", bindingResult.getAllErrors());
} else {
return new ModelAndView("users", "user", userDTO);
}
}
registration.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>User Registration</title>
<div th:replace="fragments/css_fragments :: css_background_layer"></div>
</head>
<body>
<div style="text-align:center">
<div th:replace="fragments/menu_fragments :: header_menu"></div>
</div>
<div style="margin: 0 auto; width: 20%; padding-top: 18%;">
<div class="registration-form">
<!--/*#thymesVar id="userDTO" type="com.socnetw.socnetw.model.UserDTO"*/-->
<form id="form" method="post" action="/user/save" th:object="${userDTO}">
<label>
<input name="username" placeholder="Username" required="required" th:field="*{username}"
type="text">
</label>
<ul>
<li th:each="err : ${#fields.errors('username')}" th:text="${err}"></li>
</ul>
<label>
<input name="realName" placeholder="Real Name"
type="text" th:field="*{realName}">
</label>
<ul>
<li th:each="err : ${#fields.errors('realName')}" th:text="${err}"></li>
</ul>
<span></span><br>
<label>
<input name="email" placeholder="Email" required="required" th:field="*{email}"
type="email">
</label>
<ul>
<li th:each="err : ${#fields.errors('email')}" th:text="${err}"></li>
</ul>
<label>
<input name="phoneNumber" placeholder="Phone Number" required="required" th:field="*{phoneNumber}"
type="tel">
</label>
<ul>
<li th:each="err : ${#fields.errors('phoneNumber')}" th:text="${err}"></li>
</ul>
<span></span><br>
<label>
<input name="password" placeholder="Password" th:field="*{password}"
required="required" type="password">
</label>
<ul>
<li th:each="err : ${#fields.errors('password')}" th:text="${err}"></li>
</ul>
<label>
<input name="passwordMatcher" placeholder="Repeat password" th:field="*{matchingPassword}"
required="required" type="password">
</label>
<ul>
<li th:each="err : ${#fields.errors('matchingPassword')}" th:text="${err}"></li>
</ul>
<span></span><br>
<button type="submit" style="margin-top: 20px">Register</button>
</form>
</div>
</div>
</body>
</html>
css fragment
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns="http://www.w3.org/1999/html">
<div th:fragment="css_background_layer">
<link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"
rel="stylesheet"
th:href="#{'https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css'}"
type="text/css">
<link href="css/style.css" rel="stylesheet"
th:href="#{css/style.css}"
type="text/css">
<div class="overlay"></div>
</div>
</html>
You need to use an absolute url to your css, rather than a relative one. When you go to /user/save it's looking for /user/save/css/style.css -- which probably doesn't exist.
th:href="#{/css/style.css}"
In my project, i want to make a jsp page faded when a button is clicked and show the parent(behind) page.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<style type="text/css">
<!--
.style1 {
font-family: Arial, Helvetica, sans-serif;
font-weight: bold;
font-size: 12px;
}
-->
</style>
<link href="css/buttons.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<form name="form1" method="post" action="analystServlet">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><span class="style1">Choose Source</span></td>
<td><select name="source">
<option>Excel</option>
<option>Database</option>
</select></td>
</tr>
<tr>
<td><input type="hidden" name="id" value="494"/></td>
<td> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input type="submit" class="button" onclick="hide()" name="exportHome" value="Submit"/>
</div></td>
</tr>
</table>
</form>
</body>
When i click submit button this page has be faded.
Thanks,
Karthika KM
You can do it using ajax/jquery only
function closeMe()
{
window.opener.location.reload(true); // reload parent page
window.close(); // close this page
}
$("#submitbtn").click(function(e) {
e.preventDefault();
var params = {
// here pass form parameter
};
$.ajax({
type: "POST",
url: "/analystServlet",
data: params,
success: function(data){
$('body').css("background", "rgba(0,0,0,0.5)").fadeOut("slow");
setTimeout(function () {
closeMe();
}, 1000); // 1000 = 1 secs
}
}); // end of $.ajax()
I am using struts 1.2. My struts flow is working properly but when I am using validate() method of action form for validation. my form is automatically submitted. and this validation method get called.
I am not sure this is normal behavior of struts or some configuration are missing in my application.
Please help me to understand it.
following are the config and code
<action path="/Postaddd"
type="bseller.postadd.PostaddAction"
parameter="dispatch"
scope="request"
validate="true"
name="PostadddForm">
<forward name="posterror" path="ordererror.page"/>
<forward name="successPost" path="bseller.successPost.page"/>
</action> public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
{
Logger log= Logger.getLogger("BSELLER_APPLICATION");
log.info("validate method called");
ActionErrors errors = new ActionErrors();
log.info("Email Id: " + getEmailid());
if(!Validation.isValidEmailAddress(getEmailid()))
{
errors.add("emailid", new ActionMessage("prompt.email.error"));
}
if(!Validation.isPhoneNumberValid(getMobile()))
{
errors.add("mobile", new ActionMessage("prompt.contactno.error"));
}
if(!Validation.isNumeric(getPrice()))
{
errors.add("price", new ActionMessage("prompt.price.error"));
}
return errors;
}
///////////////
<%# page contentType="text/html;charset=UTF-8" language="java"%>
<%# taglib uri="/WEB-INF/displaytag.tld" prefix="display" %>
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%# taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%# page import="bseller.utils.*" %>
<%# page import="java.util.*" %>
<%#page import="bseller.utils.CategorydetailObject"%>
<%#page import="org.apache.struts.taglib.logic.IterateTag"%><head>
<title><bean:message key="homepage.title" /></title>
<html:base />
<style type="text/css">
#import url("<%=request.getContextPath()%>/css/main.css");
#import url("<%=request.getContextPath()%>/css/submitpost.css");
</style>
<script language="javascript" src="jquery_mini.js"></script>
<script language="javascript" src="jquery.dimensions.js"></script>
<script language="javascript" src="js/Ajax_Function.js"></script>
<script language="javascript">
var name = "#floatMenu";
var menuYloc = null;
$(document).ready(function(){
menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px")))
$(window).scroll(function () {
offset = menuYloc+$(document).scrollTop()+"px";
$(name).animate({top:offset},{duration:500,queue:false});
});
});
</script>
<script>
function ret_home()
{
alert("home");
return false;
}
function ret_aboutus()
{
alert("about us");
return false;
}
function ret_contactus()
{
alert("contact us");
return false;
}
function getSubcatValue(categoryValue)
{
//alert(document.getElementById("categorySelect").Value);
document.getElementById("categorySelect").Value =categoryValue;
//alert(document.getElementById("categorySelect").Value);
//alert(categoryValue);
//var data="catvalue="+categoryValue;
//alert(data);
//datafromajax="";
// alert("before1"+datafromajax);
var url="Subcategory_Ajax.jsp?catvalue="+categoryValue;
sendRequest(url);
//alert("after"+datafromajax);
//datafromajax="";
document.getElementById("categorySelect").Value="";
}
/*function setUploadImageOption(ordertype);
{
if(ordertype=="Required")
{
//document.getElementById("UploadImage").visible= false;
document.getElementById('UploadImage').style.visibility = 'hidden';
}
}*/
function onchangeSubcat(subcatValue)
{
// alert(subcatValue);
//alert(document.getElementById("subCatSelect").Value);
document.getElementById("subCatSelect").Value =subcatValue;
//alert(document.getElementById("subCatSelect").Value);
//subcatValue=subcatValue;
}
//populatedropdown
</script>
<style type="text/css">
body {
height:2000px;
color:#111;
font:10px "Lucida Grande", "Lucida Sans", "Trebuchet MS", verdana, sans-serif;
}
#floatMenu {
position:absolute;
top:200px;
left:55%;
margin-left:235px;
width:200px;
}
#floatMenu ul {
margin-bottom:20px;
}
#floatMenu ul li a {
display:block;
border:1px solid #999;
background-color:#000;
background:'images/tab_bg1.gif'
border-left:6px solid #999;
text-decoration:none;
color:#ccc;
padding:5px 5px 5px 25px;
}
#floatMenu ul li a:hover {
color:#fff;
background-color:#333333;
}
#floatMenu ul.menu1 li a:hover {
border-color:#09f;
}
#floatMenu ul.menu2 li a:hover {
border-color:#9f0;
}
#floatMenu ul.menu3 li a:hover {
border-color:#f09;
}
</style>
</head>
<body>
<span id="er"></span>
<%!
List l;
HashMap<String ,ArrayList<CategorydetailObject>> hm =null; %>
<%
try
{
hm =(HashMap<String ,ArrayList<CategorydetailObject>>)config.getServletContext().getAttribute("PRODUCTS");
}
catch(Exception e)
{
}
%>
<input type="hidden" name="subcatfromajax" id="subcatfromajax"></input>
<DIV class=city><DIV id=welcome></DIV><DIV id=main><DIV id=block><DIV id=header><font size=4 color=blue >
Post Your Advertisement</DIV><DIV class=blank5></DIV><DIV class=blank5></DIV>
<html:messages id="" />
<html:form action="/Postaddd.do?dispatch=submitPost" method="post" enctype="multipart/form-data" >
<TABLE cellSpacing=0 cellPadding=0 width='98%'background='images/background_city.gif' border=0><TBODY>
<TR>
<TD><div class="post_ad_fonts">Email</div><div style="float:left">
<input style="width:162px" type="text" maxlength="64" name="emailid" id="emailid" class="post_ad_field" value='' />
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD><DIV id=bb1><div class="post_ad_fonts">City</div><div style="float:left">
<select class="post_ad_field" style="width:165px" name='citySelectBox' id='citySelectBox'>
<option id='0' name='0' value='0'>Select City</option>
<option name='22' id='22' value='Ahmedabad' >Ahmedabad</option><option name='211001' id='211001' value='Allahabad' >Allahabad</option><option name='23' id='23' value='Bangalore' >Bangalore</option><option name='462001' id='462001' value='Bhopal' >Bhopal</option><option name='24' id='24' value='Chandigarh' >Chandigarh</option><option name='25' id='25' value='Chennai' >Chennai</option><option name='26' id='26' value='Coimbatore' >Coimbatore</option><option name='27' id='27' value='Delhi' >Delhi</option><option name='403108' id='403108' value='Goa' >Goa</option><option name='132222' id='132222' value='Gurgaon' >Gurgaon</option><option name='580020' id='580020' value='Hubli' >Hubli</option><option name='28' id='28' value='Hyderabad' >Hyderabad</option><option name='142222' id='142222' value='Indore' >Indore</option><option name='152222' id='152222' value='Jaipur' >Jaipur</option><option name='144001' id='144001' value='Jalandhar' >Jalandhar</option><option name='831001' id='831001' value='Jamshedpur' >Jamshedpur</option><option name='421301' id='421301' value='Kalyan' >Kalyan</option><option name='208001' id='208001' value='Kanpur' >Kanpur</option><option name='29' id='29' value='Kochi' >Kochi</option><option name='30' id='30' value='Kolkata' >Kolkata</option><option name='162222' id='162222' value='Lucknow' >Lucknow</option><option name='141001' id='141001' value='Ludhiana' >Ludhiana</option><option name='625001' id='625001' value='Madurai' >Madurai</option><option name='575001' id='575001' value='Mangalore' >Mangalore</option><option name='31' id='31' value='Mumbai' >Mumbai</option><option name='32' id='32' value='Mysore' >Mysore</option><option name='172222' id='172222' value='Nagpur' >Nagpur</option><option name='422001' id='422001' value='Nashik' >Nashik</option><option name='400701' id='400701' value='NaviMumbai' >NaviMumbai</option><option name='201301' id='201301' value='Noida' selected>Noida</option><option name='800001' id='800001' value='Patna' >Patna</option><option name='33' id='33' value='Pune' >Pune</option><option name='360001' id='360001' value='Rajkot' >Rajkot</option><option name='182222' id='182222' value='Surat' >Surat</option><option name='400601' id='400601' value='Thane' >Thane</option><option name='620015' id='620015' value='Trichy' >Trichy</option><option name='695001' id='695001' value='Trivandrum' >Trivandrum</option><option name='390001' id='390001' value='Vadodara' >Vadodara</option><option name='520001' id='520001' value='Vijayawada' >Vijayawada</option><option name='531001' id='531001' value='Vizag' >Vizag</option></select>
<input type='hidden' name='city' id='city' value='201301'/>
</div>
<div class="blank10"></div>
</div>
</TD></TR>
<TR>
<TD>
<div class="post_ad_fonts">Category</div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='categorySelect' id='categorySelect'" onchange="getSubcatValue(this.value);">
<option id='0' value='0'>Select Category</option>
<%
Set<Map.Entry<String,ArrayList<CategorydetailObject>>> set =hm.entrySet();
for(Map.Entry<String,ArrayList<CategorydetailObject>> me: set)
{
String cat= me.getKey();
%>
<option name="<%=cat %>" id="<%=cat %>" value="<%=cat %>"> <%=cat %></option>
<%
}
%>
</select>
<input type='hidden' name='categorySelect' id='categorySelect' value=''/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">SubCategory</div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='subCatSelect' id='subCatSelect' onchange="onchangeSubcat(this.value);">
<option id='0' value='0'>Select SubCategory</option>
</select>
<input type='hidden' name='subCatSelect' id='subCatSelect' value=''/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<DIV id=bb1><div class="post_ad_fonts">Head Line</div>
<div style="float:left">
<input style="width:440px" type="text" maxlength="64" name="headline" id="headline" class="post_ad_field" value='' />
</div>
<div class="blank10"></div>
</div>
</TD>
</TR>
<TR>
<TD>
<DIV id=bb1><div class="post_ad_fonts">Description</div>
<div style="float:left;width :440px;">
<table border="0" style="margin:0px"><tr><td><div id="showbar">Loading Html Editor...<img src="images/ajax_loader.gif" alt="loading"/></div></td></tr></table>
<textarea name="description" id="description " onfocus="if(this.value=='Adding more detail here will help you get more responses.')this.value='';" style="width:440px;height:170px">Adding more detail here will help you get more responses.</textarea>
</div>
</div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Mobile No.<br/><span style="font-weight:normal">(Optional)</span></div>
<div style="float:left">
<input style="width:162px" type="text" maxlength="14" name="mobile" id="mobile" class="post_ad_field" value="" />
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Price<br/><span style="font-weight:normal">(Optional)</span></div>
<div style="float:left">
<input style="width:162px" type="text" maxlength="14" name="price" id="price" class="post_ad_field" value="" />
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Owner type<br/></div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='owner' id='owner'>
<option id='0' name='0' value='0'>Individual</option>
<option name='22' id='22' value='Ahmedabad' >Broker</option></select>
<input type='hidden' name='ownertype' id='ownertype' value='Individual'/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Order type<br/></div>
<div style="float:left">
<select class="post_ad_field" style="width:165px" name='order' id='order'">
<option id='0' name='0' value='Available'>Available</option>
<option name='22' id='22' value='Required' >Required</option></select>
<input type='hidden' name='ordertype' id='ordertype' value='Available'/>
</div>
<div class="blank10"></div>
</TD>
</TR>
<TR>
<TD>
<div class="post_ad_fonts">Upload Image<br/></div>
<div style="float:left" id="UploadImage">
<html:file property="image1"></html:file>
<html:file property="image2"></html:file>
<html:file property="image3"></html:file>
<input type="file" name="image4">
</div>
<div class="blank10"></div>
</TD>
</TR>
<tr><td><div class="post_ad_fonts"><br/></div><div style="float:middle"><html:submit>POST ORDER</html:submit></div> </td></tr>
</TBODY></TABLE></html:form></DIV></DIV></DIV><DIV class=blank10></DIV></DIV></DIV>
<div id="floatMenu">
<ul class="menu1">
<li> Home </li>
</ul>
<ul class="menu2">
<li> About Us </li>
<!--<li> </li>
<li> </li>-->
</ul>
<ul class="menu3">
<li> Contact Us </li>
</ul>
</div>
the validate method of actionform is always called when the form is submitted. you cannot manually call it unless you r reimplementing struts in ur own way. if u want a method to do the same work as the validate method, move the code of the validate method into another method and call it in the validate method. I do not completely understand what you are trying to do so please be more specific.
i have a jsp page with jdbc connection and on first load it shows the data accurately but after that it shows empty tables i think 2nd time it loads from memory not from server
what is problem behind i don't know
ok here are the details
i have a servlet that maintains the session for a user that log in and then after creating the session the servlet redirect the user to a view page that is a jsp page and displays the existing records in DB
when the servlet redirects the page the jsp can show the records in but when i access this page from any other html page it is unable to display the records here is the code for jsp page to view.
<%# page import="java.sql.ResultSet" %>
<%# page import="java.math.BigDecimal" %>
<%# page import="java.sql.SQLException" %>
<%# page import="java.util.logging.Level" %>
<%# page import="java.util.logging.Logger" %>
<%# page import="iEHR.cDBProcessor" %>
<HTML>
<HEAD>
<TITLE>View Patient</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1251">
<script type="text/javascript" language="javascript" src="datepicker/main.js"></script>
<script type="text/javascript" language="javascript" src="datepicker/prototype-1.js"></script>
<script type="text/javascript" language="javascript" src="datepicker/prototype-base-extensions.js"></script>
<script type="text/javascript" language="javascript" src="datepicker/prototype-date-extensions.js"></script>
<script type="text/javascript" language="javascript" src="datepicker/behaviour.js"></script>
<script type="text/javascript" language="javascript" src="datepicker/ratingbar.js"></script>
<script type="text/javascript" language="javascript" src="datepicker/datepicker.js"></script>
<link rel="stylesheet" href="datepicker/datepicker.css">
<script type="text/javascript" language="javascript" src="datepicker/behaviors.js"></script>
<style type="text/css">
<!--
img {
border: none;
}
.tah10 {
font-family: "Times New Roman", Times, serif;
font-size: 14px;
text-decoration: none;
color: #000000;
font-style: italic;
}
.tah11 {
font-family: Tahoma;
font-size: 11px;
text-decoration: none;
color: #000000;
}
.ver10 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
text-decoration: none;
color: #000000;
}
.ver11 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 11px;
text-decoration: none;
color: #000000;
}
.tah9 {
font-family: Tahoma;
font-size: 9px;
text-decoration: none;
color: #000000;
}
.ver9 {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 9px;
text-decoration: none;
color: #000000;
}
td {
vertical-align: top;
color: 497B99;
font-size: 12px;
font-style: normal;
font-weight: bolder;
}
-->
</style>
<style type="text/css">
<!--
.bgtop {
background-repeat: repeat-x;
background-position: top;
}
-->
</style>
<style type="text/css">
<!--
a {
font-family: Times New Roman, Times, serif;
font-size: 12px;
font-weight: bolder;
color: 467B99;
text-decoration: none;
}
.datepicker{
font-family: Times New Roman, Times, serif;
font-size: 12px;
font-weight: bolder;
color: 467B99;
text-decoration: none;
}
a:hover {
font-size: 10px;
font-weight: bold;
color: FF8400;
}
.style1 {
color: 467B99;
font-family: Times New Roman, Times, serif;
font-size: 12px;
text-decoration: none;
font-style: normal;
font-weight: bolder;
}
.style2 {
font-family: Times New Roman, Times, serif;
font-size: 12px;
font-style: normal;
font-weight: bolder;
color: 467B99;
text-decoration: none;
}
-->
</style>
</HEAD>
<BODY BGCOLOR=#FFFFFF LEFTMARGIN=0 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<!-- ImageReady Slices (0005_red.psd - Slices: 03, 04, 05) -->
<TABLE WIDTH=100% height="100%" BORDER=0 CELLPADDING=0 CELLSPACING=0 bgcolor="#FFFFFF">
<TR>
<TD width="12%">
<TABLE WIDTH=159 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD COLSPAN=6>
<IMG SRC="images/logo.gif" WIDTH=159 HEIGHT=128 ALT=""></TD>
</TR>
<TR>
<TD>
<IMG SRC="images/s1.gif" WIDTH=20 HEIGHT=20 ALT=""></TD>
<TD>
<A HREF="#">
<IMG SRC="images/r1.gif" WIDTH=29 HEIGHT=20 BORDER=0 ALT=""></A></TD>
<TD>
<A HREF="#">
<IMG SRC="images/r2.gif" WIDTH=31 HEIGHT=20 BORDER=0 ALT=""></A></TD>
<TD>
<A HREF="#">
<IMG SRC="images/r3.gif" WIDTH=31 HEIGHT=20 BORDER=0 ALT=""></A></TD>
<TD>
<A HREF="#">
<IMG SRC="images/r4.gif" WIDTH=28 HEIGHT=20 BORDER=0 ALT=""></A></TD>
<TD>
<IMG SRC="images/s2.gif" WIDTH=20 HEIGHT=20 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=6>
<IMG SRC="images/s3.gif" WIDTH=159 HEIGHT=93 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=6>
<IMG SRC="images/h1.jpg" WIDTH=159 HEIGHT=32 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=6>
<IMG SRC="images/img1.jpg" WIDTH=159 HEIGHT=76 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=6>
<IMG SRC="images/img2.jpg" WIDTH=159 HEIGHT=81 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=6>
<IMG SRC="images/img3.jpg" WIDTH=159 HEIGHT=79 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=6> <IMG SRC="images/but1.jpg" ALT="" WIDTH=159 HEIGHT=42 border="0" usemap="#Map"></TD>
</TR>
</TABLE> </TD>
<TD width="12%">
<TABLE WIDTH=167 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD COLSPAN=2>
<IMG SRC="images/h2.jpg" WIDTH=167 HEIGHT=25 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg1.gif" HEIGHT=94>
<div style="padding:20;padding-top:5;padding-right:10;padding-bottom:0;color:ffffff" class="tah10">
<strong>Noesis</strong><br><br>
<strong>Inovative EHR Services </strong> <br>
<br>
</div> </TD>
</TR>
<TR>
<TD COLSPAN=2>
<IMG SRC="images/s4.jpg" WIDTH=167 HEIGHT=52 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg2.gif">
<div style="padding-left:0px;padding-top:12px;padding-bottom:2"><span style="padding-left:20;padding-top:5">Add Patient </span></div> </TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg3.gif" HEIGHT=18>
<div style="padding-left:20;padding-top:5">Add Patient History </div>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg4.gif" HEIGHT=18>
<div style="padding-left:20;padding-top:5">Add Patient Insurance</div> </TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg5.gif" HEIGHT=18 >
<div style="padding-left:20;padding-top:5">View Patient Records</div></TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg6.gif" HEIGHT=18 >
<div style="padding-left:20;padding-top:5">About Us</div> </TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg7.gif" HEIGHT=18 >
<div style="padding-left:20;padding-top:5">Contact Us</div> </TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg8.gif" HEIGHT=18 >
<div style="padding-left:20;padding-top:5"></div> </TD>
</TR>
<TR>
<TD COLSPAN=2>
<IMG SRC="images/h3.gif" WIDTH=167 HEIGHT=65 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=2 background="images/bg9.gif" HEIGHT=94>
<div style="padding:15;padding-top:3;padding-bottom:3;color:737373" class="tah10"></div> </TD>
</TR>
<TR>
<TD COLSPAN=2>
<IMG SRC="images/h4.jpg" WIDTH=167 HEIGHT=41 ALT=""></TD>
</TR>
<TR>
<TD background="images/bg10.jpg" WIDTH=123 HEIGHT=32>
<div style="padding-left:15;padding-top:1">
<input name="text" type="text" size="11">
</div></TD>
<TD width="44"> <IMG SRC="images/but2.jpg" ALT="" WIDTH=44 HEIGHT=32 border="0" usemap="#Map2"></TD>
</TR>
<TR>
<TD COLSPAN=2>
<IMG SRC="images/s5.jpg" WIDTH=167 HEIGHT=48 ALT=""></TD>
</TR>
<TR>
<TD COLSPAN=2> </TD>
</TR>
</TABLE> </TD>
<TD width="72%">
<table width=100% height="193" border=0 cellpadding=0 cellspacing=0>
<tr>
<td height=172 colspan="4" ><span class="bgtop"><img src="images/f_m.jpg"></span></td>
<td height=172 colspan="2" width="63%" background="images/bg_tile_1.gif" class="bgtop"> </td>
</tr>
<tr>
<td height=19 colspan="4" background="images/bg11.gif" > </td>
</tr>
</table>
<%! private ResultSet rsResult; %>
<%! cDBProcessor DBProcess = new cDBProcessor(); %>
<%
DBProcess.ConnectTODB();
if(request.getAttribute("dbrec") != null)
{
rsResult = DBProcess.statement.executeQuery("SELECT * FROM patients");
}//end if
out.println("<table border=\"0\"><tr><td valign=\"top\" >");
out.println("<tr><th>Patient ID</th><th>First Name</th><th>Middle Name</th><th>Last Name</th><th>Gender</th><th>Marital Status</th><th>Phone No.</th><th>Address</th>");
out.println("<th>Date Of Birth</th><th>Last Date Of Exam</th><th>Status</th></tr>");
//data display on page
if(rsResult!= null)
{
try
{
while (rsResult.next())
{
BigDecimal bdPatientID = rsResult.getBigDecimal("patient_id");
String strFirstname = rsResult.getString("first_name");
String strLastname = rsResult.getString("last_name");
String strMiddlename = rsResult.getString("middle_name");
String strGeneder = rsResult.getString("gender");
String strMeritalStatus = rsResult.getString("marital_status");
BigDecimal bdPhoneNo = rsResult.getBigDecimal("phone_no");
String strAddress = rsResult.getString("address");
String strDOB = rsResult.getDate("birth_dt") == null ? "" : rsResult.getDate("birth_dt").toString();
String strDOE = rsResult.getDate("dt_of_exam") == null ? "" :rsResult.getDate("dt_of_exam").toString();
String strStatus;
Byte bPatientStatus= rsResult.getByte("status");
if(bPatientStatus == 1)
{
strStatus = "Active";
}//end if
else
{
strStatus = "Inactive";
}//end else
out.println("<tr><td>"+bdPatientID+"</td><td>"+strFirstname+"</td><td>"+strMiddlename+"</td><td>"+strLastname+"</td>");
out.println("<td>"+strGeneder+"</td><td>"+strMeritalStatus+"</td><td>"+bdPhoneNo+"</td><td>"+strAddress+"</td>");
out.println("<td>"+strDOB+"</td><td>"+strDOE+"</td><td>"+strStatus+"</td></tr>");
}//end while
out.println("</table>");
}//end try
catch (SQLException ex)
{
out.println("<I>exception</I><br>");
}//end catch
}//end if
DBProcess.CloseDB();
%>
</TD>
<TD width="4%" background="images/bg_tile_1.gif" class="bgtop"> </TD>
</TR>
<TR>
<TD height="100%" colspan="4"> </TD>
</TR>
<TR>
<TD colspan="3">
<TABLE WIDTH=768 BORDER=0 CELLPADDING=0 CELLSPACING=0>
<TR>
<TD width="326">
<IMG SRC="images/s7.gif" WIDTH=326 HEIGHT=48 ALT=""></TD>
<TD background="images/bg16.gif" WIDTH=442 HEIGHT=48>
<div style="padding-top:12;color:A8A8A8" class="tah11">
2010 © Copyright iAS. <Br>
All rights Reserved. Read Privacy Policy.</div> </TD>
</TR>
</TABLE> </TD>
<TD width="4%" background="images/bg_tile_2.gif"> </TD>
</TR>
</TABLE>
<!-- End ImageReady Slices -->
<map name="Map">
<area shape="rect" coords="39,2,133,27" href="#">
</map>
<map name="Map2">
<area shape="circle" coords="9,12,9" href="#">
</map>
</BODY>
</HTML>
It smells like threadsafety/scoping problem. You've declared the ResultSet and DBProcess as instance variable of the JSP using <%! %> scriptlet declarations, so it's been shared among all HTTP requests. I am not sure about the DBProcess, but this is certainly a bad idea for ResultSet (and also for Connection and Statement by the way). How the DBProcess is been used in the remnant of the code is also pretty scary, e.g. DBProcess.statement.executeQuery(). Is the Statement really a public field? I don't know how the class' internals look like, but yes, this smells too much like threadsafety/scoping problem.
Also, this 90's style writing of HTML and using scriptlets in JSP really don't suit a "Copyright 2010" application. Are you reading the right tutorials/books?
beside those issues pointed out by BalusC,
base on the described symptom "when the servlet redirects the page the jsp can show the records in but when i access this page from any other html page it is unable to display the records" and code "if(request.getAttribute("dbrec") != null) ".
My prime suspect for the issue's cause is the use of request.getAttribute("dbrec")
for those direct access from other html page, this value likely to be null. I suspect for redirect case, there may be some code that perform request.setAttribute("dbrec",....)