Gremlin2
September 4th, 2001, 01:01 PM
Does anyone know how to invoke a jsp page from a servlet, transfering data from the Servlet to the JSP page?
Thanx
Thanx
|
Click to See Complete Forum and Search --> : Servlet to jsp Gremlin2 September 4th, 2001, 01:01 PM Does anyone know how to invoke a jsp page from a servlet, transfering data from the Servlet to the JSP page? Thanx Wanton Killer September 5th, 2001, 02:28 AM Hi, here are the code lines to put in your servlet RequestDispatcher rd = getSErvletContext().getRequestDispatcher("somename.jsp"); rd.forward(request, response); if you want to transfer data to the request put the folowing before the secone line above request.setAttribute("attName", attribute); Cheers! Wanton killer Gremlin2 September 5th, 2001, 06:09 AM Great, thanks! Gremlin2 September 5th, 2001, 10:58 AM Hi again, How do I access the data in the .jsp page? This doesn't seem to work, just returns null! <%= request.getParameter("lname")%> The servlet code is as follows: RequestDispatcher rd = getServletContext().getRequestDispatcher("/test.jsp"); req.setAttribute("lname", lname); rd.forward(req, res); Thanx bayard September 5th, 2001, 11:49 AM <%= request.getAttribute("lname") %> bear in mind it's an Object and not just a String from getAttribute. Bayard bayard@generationjava.com http://www.generationjava.com Brainbench MVP for Java http://www.brainbench.com codeguru.com
Copyright WebMediaBrands Inc., All Rights Reserved. |