File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes How to forward to other JSP when we use include Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to forward to other JSP when we use include " Watch "How to forward to other JSP when we use include " New topic
Author

How to forward to other JSP when we use include

Suren Raj
Greenhorn

Joined: Jan 24, 2003
Posts: 8
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

Joined: Mar 06, 2001
Posts: 13459

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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to forward to other JSP when we use include