• 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

forward method in jsp

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is forward method in pagecontext is supposed to append to response object ???

Gunjan
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure I understand exactly what you asked, but this code snippet shows how to forward a request.

public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{

......

RequestDispatcher rd =
req.getRequestDispatcher("hello.jsp");

try {
rd.forward(req,res);
} catch (ServletException e) {}


}
Cheers,
Dan
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
it does foward the response object
 
GK
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have two jsp - 1.jsp and 2.jsp
1.jsp
-----
out.println("b4 forward");
pageContext("2.jsp");
out.println("after forward");
2.jsp
-----
out.println("in 2.jsp");

what will be the output if i run 1.jsp
Gunjan
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are lucky, and you have not committed the response (by overflowing the output buffer), you will get a single line of output:
"in 2.jsp"

If the forwarding page was buffered, the buffer is cleared prior to the forward (so say goodbye to "in 1.jsp"). If the page is unbuffered, or you've overflowed the buffer, you will get an IllegalStateException when you try to forward.

You will never see "after forward" because a forward does not return control to the forwarding page. Including a page does though, and does not have the buffering problem either.

And here is the code to forward:
[This message has been edited by Mike Curwen (edited October 17, 2001).]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic