• Post Reply Bookmark Topic Watch Topic
  • New Topic

communication Between two servlets  RSS feed

 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i pass some value from a servlet to a JSP if the request dispatch mode is
response.sendRedirect.
 
Ankit Garg
Sheriff
Posts: 9608
36
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"));
 
abinash das
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!