Fade a JSP page - java

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()

Related

How can I solve NullPointerException using ModelAndView object?

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-

Edit specific row of a table using id of that row without database operations using jquery

Edit specific row of a table using id of that row without database operations.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<link href="styleKMF.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://prototype.xsanisty.com/calx/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://prototype.xsanisty.com/calx/jquery-calx-1.1.8.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="addRow.js"></script>
<script type="text/javascript">
var currentRow = 1;
$(document).ready(function(){
$('#calx').calx();
//insert row
$('#irow').click(function(){
if($('#G1').val()){
$('#list tbody').append($("#list tbody tr:last").clone());
$('#list tbody tr:last td:first').html($('#G1').val());
$('#list tbody tr:last td:last').html($('#H1').val());
$('#list tbody tr:last td:last').html($('#I1').val());
$('#list tbody tr:last td:last').html($('#J1').val());
$('#list tbody tr:last td:last').html($('#E1').val());
}
});
//Edit a specific row based on id and update it
$("td", this).on("click", function () {
var tds = $(this).parents("tr").find("td");
$.each(tds, function (i, v) {
$($("#myForm input")[i]).val($(v).text());
});
});
});
</script>
</head>
<body>
<div id="container">
<div id="calx">
<div id="spacer"></div>
<form name="serviceForm" >
<label for="serviceName">Service Name:</label>
<select name="particulars" id="G1">
<%
try{
Connection connection = DBConnectionManager.getConnection();
CallableStatement callableStatement = connection.prepareCall("{ CALL get_master_services(?)}");
callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
callableStatement.execute();
ResultSet rs = (ResultSet) callableStatement.getObject(1);
while(rs.next()){
String id1 = rs.getString("service_desc");
%>
<option value="<%=id1 %>"><%=id1 %></option>
<%
}
}
catch(Exception e)
{
out.println("wrong entry"+e);
}
%>
</select><br><br>
<label for="month">Month:</label>
<select name="month" id="H1">
<option>Select Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<label for="year">Year:</label>
<select name="year" id="I1">
<option>Select Year</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
</select><br><br>
<td>
<label for="details">Details:</label>
<input type="text" name="details" id="J1" style="width:'50px';">
</td><br><br>
<tr>
<td><label for="Tax">Tax:</label><input type="text" id="B1" value="" data-format="0,0[.]00" /></td><br><br>
<td><label for="Tax">Cess:</label><input type="text" id="C1" value="" data-format="0,0[.]00" /></td><br><br>
<td><label for="Tax">Interest/Penality:</label><input type="text" id="D1" value="" data-format="0,0[.]00 " /></td><br><br>
<td><label for="Tax">Total:</label><input type="text" name="total" id="E1" value="" data-format="0,0[.]00" data-formula="($B1+$C1+$D1)" /></td><br>
</tr>
<tr>
<td><input type="button" id="irow" value="Add" onclick="Javascript:addRow()" ></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</form>
<hr>
<table id="list" border="1" >
<tr>
<td>Service Name</td>
<td>Month</td>
<td>Year</td>
<td>Details</td>
<td>Amount</td>
<td> </td>
</tr>
</table>
<!-- <tr>
<td colspan="6" style="text-align: right">Total Price :</td>
<td id="F1" data-format="0,0[.]00" data-formula="SUM($E1,$E5)"></td>
</tr>-->
</div>
</div>
</body>
i have done this using jquery also, but displaying only first and last column values, but not the between columns. How can i display between columns and how can i edit row after displaying values using jquery. How to fetch that specific row values on to the form?
using equal you can pass index of tr and get object of particular tr. same way in td
see below example
$('#list tbody tr:eq(1) td:eq(0)').html();

Clear Cart button in Java

Hi I'm trying to make a "Clear Cart" button in my java code but i'm having difficulty.
I've been trying for a couple of hours but i can't get it to work
I think it has something to do mostly with the first part that has all the strings and variables.
Here's the code:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%# page errorPage="errorpage.jsp" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>the Game Store</title>
</head>
<body>
<%
String id = request.getParameter("id");
if ( id != null ) {
String desc = request.getParameter("desc");
Float price = new Float(request.getParameter("price"));
cart.addItem(id, desc, price.floatValue(), 1);
}
%>
Shopping Cart Quantity:
<%=cart.getNumOfItems() %>
<hr>
<center><h3>Games</h3></center>
<table border="1" width="300" cellspacing="0"
cellpadding="2" align="center">
<tr><th>Description</th><th>Price</th></tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<td>Goat Simulator</td>
<td>$11.95</td>
<td><input type="submit" name="Submit" value="Add"></td>
<input type="hidden" name="id" value="1">
<input type="hidden" name="desc" value="Goat Simulator">
<input type="hidden" name="price" value="11.95">
</form>
</tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<td>Metal Gear Solid V</td>
<td>$59.99</td>
<td><input type="submit" name="Submit" value="Add"></td>
<input type="hidden" name="id" value="2">
<input type="hidden" name="desc" value="Metal Gear Solid V">
<input type="hidden" name="price" value="59.99">
</form>
</tr>
<tr>
<form action="AddToShoppingCart.jsp" method="post">
<input type ="submit" name="empty" id="empty-button" value="Empty Cart"/>
</form>
Clear
</tr>
</table>
</body>
</html>
Here's the second page for the entire page
<%# page errorPage="errorpage.jsp" %>
<%# page import="java.util.*" %>
<jsp:useBean id="cart" scope="session" class="beans.ShoppingCart" />
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<title>Shopping Cart Contents</title>
</head>
<body>
<center>
<table width="300" border="1" cellspacing="0"
cellpadding="2" border="0">
<caption><b>Shopping Cart Contents</b></caption>
<tr>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
</tr>
<%
Enumeration e = cart.getEnumeration();
String[] tmpItem;
// Iterate over the cart
while (e.hasMoreElements()) {
tmpItem = (String[])e.nextElement();
%>
<tr>
<td><%=tmpItem[1] %></td>
<td align="center">$<%=tmpItem[2] %></td>
<td align="center"><%=tmpItem[3] %></td>
</tr>
<%
}
%>
</table>
</center>
Back to Catalog
</body>
</html>

Struts form automatically submitted when using validate() method

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.

how to reload jsp page on every request?

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",....)

Categories

Resources