• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to forward to other JSP when we use include

 
Suren Raj
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reader,
This is the piece of code i have in my servlet..
RequestDispatcher disp = getServletContext().getRequestDispatcher("/Normal.jsp");
disp.include(req, res);
String sStatus = (String) req.getAttribute("Status");
String name= "";
if (!sStatus.equals("OK")){
res.sendRedirect(sStatus);
}
else{
name = (String) req.getAttribute("Name");
}
When the status is not 'Ok' it basically throws an illegal state exception. I guess the response is committed. But how to get rid of this scenario.
What should i do so that i can include a JSP file in my servlet and eventually i can use forward or redirect to another JSP ? Is there really a way to work it out ?
Thanks in advance guys
Suren
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to decide what to display before you display anything.
In your case, you aren't sure what to display, but you are including a file then deciding what you really wanted was to redirect.
This may still not be what you need, but it removes that conflict.

The other thing to try out is making the redirect/include/forward the last thing you do in the servlet. Try not to have any processing after these calls and again it just makes life a little easier.
Dave
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic