Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet to JSP

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But what do I do to set the name and bdate to the response object?
 
Winston Smith
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you forward the page to the JSP, the JSP can access the parameters just as you did before, using request.getParameter().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic