aspose file tools*
The moose likes JSP and the fly likes Servlet to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Servlet to JSP" Watch "Servlet to JSP" New topic
Author

Servlet to JSP

Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
I have a servlet in which I use-
String name = request.getParameter("name");
String bdate = request.getParameter("bdate");
I would like to send this information to a JSP page- Welcome.jsp which displays the name and bdate.
What are the lines of code I would use in my servlet to send this information to the JSP?
How should I retrieve the information in the JSP in order to display it?
Srinivas Jag
Greenhorn

Joined: Jun 30, 2003
Posts: 9
You can use
RequestDispatcher rd = req.getRequestDispatcher("<Your JSP file>");
rd.forward(req, res);
In your JSP page, the request paramters from the servlet will be available, and can be retrieved by calling getParameter on the implicit "request" object.
Instead of using the request object to get the RequestDispatcher in the servlet, you can also use the ServletContext object which defines the same method to retrieve the request dispatcher.
Lucky Singh
Ranch Hand

Joined: Jan 19, 2004
Posts: 125
But what do I do to set the name and bdate to the response object?
Winston Smith
Ranch Hand

Joined: Jun 06, 2003
Posts: 136
Once you forward the page to the JSP, the JSP can access the parameters just as you did before, using request.getParameter().


for (int i = today; i < endOfTime; i++) { code(); }
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet to JSP