• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to forward to other JSP when we use include

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic