Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

forward method in RequestDispatcher

Status
Not open for further replies.

lowbk

Technical User
Nov 26, 2001
162
SG
hi guys,
i've a jsp that will activate a servlet when the submit button is clicked. after the servlet has done its processing, it forward to another jsp for displaying

JSP1 => Servlet1 => JSP2

inside the servlet, i'm using the following method
getServletContext().getRequestDispatcher("/JSP2.jsp").forward(request, response);

suppose the form with JSP1 contains 5 components, and i can access them in Servlet1 using "request.getParameter(paraname)" or "request.getParameterNames()".

my question is when JSP2 is activated, are these form components in JSP1 sent over to JSP2? ie can i use request.getParameter(paraname) in JSP2 to get the value within paraname?

any kind soul pls advise
 
Yes, the HttpServletRequest object is forwarded directly to the specified JSP so you can pick off any parameters with getParameter() and so forth. Furthermore you can add additional information to the request in the Servlet by using setAttribute(). The common method is to do all of the data processing and business logic in the Servlet Layer via regular Java Classes and/or EJB and then place the finished product to display as a Request Attribute. In this case the Display JSP will just pick out the Attribute and render it without touching the actual HTML Parameters. This is the basics of the Model-View-Controller(MVC) Architecture. This keeps your JSPs completely decoupled from each other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top