This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

grabbing a parameter in jsp  RSS feed

 
Jeff Sunder
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing an application where I am using a servlet as a controller. From the servlet I forward to a jsp page. But I would like to pass a few variables from the servlet to the jsp. In the servlet, I appended the variables to the request by doing the following: request.setAttribute("var1", var1) then use the dispatcher to forward the page to the jsp.
But how can I access the variables (i.e. var1) in the JSP?
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Simple, Lets say you set a String in the servlet, in your jsp you place the code:
String fromServlet = (String)getAttribute("keyNameUsedInServlet);
You can set any object in the attributes and as long as you use of reference of the right type and cast it properly, it is now available in your JSP page.
------------------
Hope This Helps
Carl Trusiak, SCJP2
 
Jayson Falkner
Author
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are interested in a complete example of the above code check out this FAQ.
http://www.jspinsider.com/faq/12.view
Jayson Falkner
jayson@jspinsider.com
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!