Two Laptop Bag
The moose likes Servlets and the fly likes Problem with sendRedirect() Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Problem with sendRedirect()" Watch "Problem with sendRedirect()" New topic
Author

Problem with sendRedirect()

vishwas madhuvarshi
Greenhorn

Joined: Jan 21, 2001
Posts: 16
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

Joined: Feb 02, 2001
Posts: 14
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

Joined: Jan 12, 2001
Posts: 639
the code :
<%
response.sendRedirect(" the iurl where you wanna go");
%>

Raghav.
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Mar 13, 2001
Posts: 14
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
 
 
subject: Problem with sendRedirect()
 
Threads others viewed
different between parameters and attributes
how to keep input when back to this page?
jsp:param with jsp:include
jspInit() method
Check and Passing Values
developer file tools

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture