• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with sendRedirect()

 
vishwas madhuvarshi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have one index page in my site where the user has to verify himself with name and password, then this information is passed to a servlet which matches the same against a database. From here I want to transfer the request to a JSP with response.sendRedirect() method. The JSP page is called but request parameters are not available here. How caN i make request parameters available in this page also?
 
James Long
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to do the following:
(1). In servlet:
----- request.setAttribute("YourParameter");
--- getServletConfig().getServletContext().getRequestDispatcher("YourJspPageReativeURL").forward(req,res);
(2). In JSP:
String parameter = request.getAttribute("YourParameter");
......
I hope it will help you!
Good Luck
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code :
<%
response.sendRedirect(" the iurl where you wanna go");
%>
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raghav, I think you missed the point -- request parameters normally don't survive a redirect. Of course you can add parameters to a redirect, as to any request:
response.sendRedirect("http://url/page.jsp?parameter=blah");
But in this case it looks like a forward is more appropriate.
- Peter
 
sachin sachdeva
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When we uses sendredirect then it does not passe the values to next page.For this either u can use forward or sendRedirect("uri+querystring)
Means by only querystring u can pass the values in sendRedirect
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic