Hello everyone,
The problem I have is the following in detail.
I have one page to let user to select the table name in the database, the user Go the second page (ModifyForm.jsp) to modify Employee data and using POST method to submit to ModifyServlet to Update the Employee data in the database table. Then ModifyServlet return back to the ModifyForm.jsp and let the user to continue to modify the Employee data.
The database table name from the firstPage's (there is a form) request parameter (at the First Time) or from the ModifyServlet's request attribute (not the first time access the ModifyForm.jsp).
My ModifyForm.jsp is like the following:
========================================
String tableName = null;
if(request.getAttribute("tableName") != null){
tableName =request.getAttribute("tableName");
}else if(request.getParameter("tableName")){
tableName = request.getParameter("tableName");
}else{
tableName = "Employee"; <%-- Default table name --%>
}
<FORM name="modifyForm" action="/MyApplication/servlet/ModifyServlet" method="post" >
Imployee ID: <INPUT type="text" name="empID" value="">
Last Name: <INPUT type="text" name="lname" value="">
First Name: <INPUT type="text" name="fname" value="">
Address: <INPUT type="text" name="address" value="">
<INPUT type="hidden" name="tableName" value="<%= tableName %>">
<INPUT type="submit" name="action" value="Modify">
</Form>
==============================================
There is a hidden field in this form called "tableName",
which is used to update the database "Employee" table data.
After the user change the address, fill in their name
in the above form and click the "SUBMIT" button.
ModifyServlet is called, after it update the database table successfully, the ModifyServlet called the following method to redirect back to the ModifyForm page in order for user to modify the another Employee data
==========================================
...... // Update database table
String tableName = request.getParameter("tableName");
.....
request.setAttribute("tableName", tableName);
getServletConfig().getServletContext().getRequestDispatcher
.("/jsp/ModifyForm.jsp").forward(req,res);
======================================
The problem is that if I first time to click "Modify" button,
it works fine.
But if I continue to click the "Modify" button in the returned ModifyForm page from the ModifyServlet. In the broswer URL address keep the same as I first submit the form. i.e.:
http://localhost:8080/MyApplication/servlet/ModifyServlet Sometimes I continue to click the "Modify" button in the returned ModifyForm page for 10 or more times, there is no problem. But sometimes if I clicked the second time or the fifth time on the "Modify" button in the returned ModifyForm.jsp page. Error.jsp is shown. I found there was no hidden field values in the ModifyForm passed to ModifyServlet from ModifyForm.
In this case my ModifyServlet throw a Exception called MyException,
JSP error page will catch it and tell me that the hidden field value for table name passed from the ModifyForm to ModifyServlet is null.
In error.jsp page there is a BACK button, If BACK button is clicked, the web broswer can go back to the previous page. But after the above Exception is throwed, I clicked the BACK button, and the web browser give the following messages:
=============================================================
Warning: Page has Expired The page you requested was created using information you submitted in a form.
This page is no longer available. As a security precaution, Internet Explorer does not automatically resubmit your information for you.
To resubmit your information and view this Web page, click the Refresh button.
==============================================================
The above jsp error page is not always to be present because the hidden fields value can be passed into ModifyServlet properly. But sometimes jsp error page will be shown just second time I clicked the "Modify" button. But even it will never happen.
I don't know why hidden field didn't be passed to the
Servlet.
May it possible not be passed from the ModifyServlet to ModifyForm.jsp back through calling request.setAttribute("tableName", tableName)?
Thank you for any one who can help me to solve this problem.
What do I need to change?
Best Regards
W. Long