File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "communication Between two servlets" Watch "communication Between two servlets" New topic

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
Ankit Garg

Joined: Aug 03, 2008
Posts: 9452

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


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


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).
It is sorta covered in the JavaRanch Style Guide.
subject: communication Between two servlets
It's not a secret anymore!