This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have a JSP page which will post to a servlet upon clicking the "submit" button. The servlet will perform some processing and then redirect back to the JSP with all the original form fields prefilled. Which means i need to have a means for "transferring" a fair amount of data values from JSP to servlet back to JSP so i cannot append the data as querystring behind my Url when i do a response.sendRedirect() from my servlet to JSP. In my servlet, i have the below code. I try to set the values into a session before i use a response.sendRedirect() to direct back to the JSP. But in the JSP, i don't seems to be able to retrieve back the session values that i have set in the servlet.
hi, instead of using sendRedirect use RequestDispatcher to tranfer the control. RequestDispatcher is the preferred method to transfer the control as far as my experience is concerned. try out and let me know. regards, ravi
Please check if u have created a session, when u access your servlet for the first time. HttpSession session=request.getSession(true); a beter way to do this is to use RequestDispatcher code--- RequestDispatcher rd = request.getRequestDispatcher("JSP path"); rd.forward(request,response); --You dont need to store the values in a session, cause u get access to the orignal request object.
Joined: Apr 05, 2004
yup it works. I use ServletContext sc = getServletContext(); RequestDispatcher rd = sc.getRequestDispatcher("/jsppage.jsp"); request.setAttribute("resp","success"); rd.forward(request, response); Thanks for all the help!!!