At the top of my doPost method I grab a few parameters that I previously set in the JSP using a basic form:
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String serverName = request.getParameter("serverName");
String destFileName = request.getParameter("destFileName");
String userName = request.getParameter("userName");
String Message= request.getParameter("Message");
and at the end of the doPost method I add them back to the request object using setAttribute:
request.setAttribute("userName ", userName );
request.setAttribute("destFileName", destFileName);
request.setAttribute("serverName", serverName);
request.setAttribute("Message", Message);
request.getRequestDispatcher(page).forward(request, response);
And then I get them in my JSP via request.getParameter again:
<% /** if the parameters are already in place, grab them **/
String destFileName = request.getParameter("destFileName");
String user = request.getParameter("user");
String serverName = request.getParameter("serverName");
String Message = request.getParameter("Message");
%>
And this works, unless I've rewritten the value on its way through the doPost method. If that is the case, then I have to use request.getAttribute in the JSP to retrieve it since request.getParameter will retrieve the value as it was defined at the top of the doPost method, ignoring any changes that were made between the top and the bottom.
Does anyone have an explanation of this? I've got everything working, but I'd like to understand why I spent a couple of hours of frustration figuring out what was wrong.