aspose file tools*
The moose likes Servlets and the fly likes response.sendRedirect Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "response.sendRedirect" Watch "response.sendRedirect" New topic
Author

response.sendRedirect

anis mistry
Ranch Hand

Joined: Nov 11, 2000
Posts: 52
i have this problem of response.sendRedirect method
from a servlet A i am sending redirect to servlet B
servlet B's post method contains only these lines
PrintWriter out;
out=res.getWriter();
out.println("you are in CreditCard servlet");
but this line 'you are in CreditCard servlet' is not shown instead error is shown on the page ie The page cannot be found
servlet B's init() method also gets invoked which is shown in the servletrunner
why does this error occurs please explain
thank you
Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
I think it's possible that is because you didn't set the ContentType.
ashok khandelwal
Greenhorn

Joined: Dec 18, 2000
Posts: 6
Originally posted by anis mistry:
i have this problem of response.sendRedirect method
from a servlet A i am sending redirect to servlet B
servlet B's post method contains only these lines
PrintWriter out;
out=res.getWriter();
out.println("you are in CreditCard servlet");
but this line 'you are in CreditCard servlet' is not shown instead error is shown on the page ie The page cannot be found
servlet B's init() method also gets invoked which is shown in the servletrunner
why does this error occurs please explain
thank you

hi
i am sending u the code for sendRedirect
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class redirect extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String name=request.getParameter("UName");
if(name.equals("infobahn"))
{

response.sendRedirect("http://infobahn:8080/login1.html");
}
else
{
response.sendRedirect("http://infobahn:9090/ashok/error.html");
}

}
}
Danny Mui
Ranch Hand

Joined: Dec 14, 2000
Posts: 42
Try putting the code in the doGet() method. I think that redirects are inherent gets and not posts.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: response.sendRedirect