• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Servlet to JSP

 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But what do I do to set the name and bdate to the response object?
 
Ranch Hand
Posts: 136
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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().
 
reply
    Bookmark Topic Watch Topic
  • New Topic