This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

response.sendRedirect

 
anis mistry
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 177
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's possible that is because you didn't set the ContentType.
 
ashok khandelwal
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try putting the code in the doGet() method. I think that redirects are inherent gets and not posts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic