This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes communication Between two servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "communication Between two servlets" Watch "communication Between two servlets" New topic
Author

communication Between two servlets

abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52
How can i pass some value from a servlet to a JSP if the request dispatch mode is
response.sendRedirect.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

You can add parameters to the url that you give in the sendRedirect method like this

response.sendRedirect("/myPage.jsp?param="+myParam);

Or you can set the value in a session attribute and retrieve it in the other servlet but for that you'll have to encode the redirect url with the session id

response.sendRedirect(reponse.encodeRedirectURL("/myPage.jsp"));


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
abinash das
Ranch Hand

Joined: Apr 26, 2008
Posts: 52


In the given techinque

i,e response.sendRedirect(reponse.encodeRedirectURL("/myPage.jsp"));

how can i pass values to myPage.jsp.
maens how to define and set values and how to get these values at myPage.jsp
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
When redirecting, pass it as request parameters (visible in URL).
When forwarding, pass it as request attributes (hidden from URL).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: communication Between two servlets