This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes forward method in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "forward method in jsp" Watch "forward method in jsp" New topic
Author

forward method in jsp

GK
Greenhorn

Joined: Jan 25, 2001
Posts: 26
Is forward method in pagecontext is supposed to append to response object ???

Gunjan
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1167
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


William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
it does foward the response object
GK
Greenhorn

Joined: Jan 25, 2001
Posts: 26
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
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

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).]
 
 
subject: forward method in jsp
 
Similar Threads
WA #1.....word association
How can I forward the from doPost to doGet
How to invoke struts action through a simple java class
enable/disable Buttons
forward in jsdk 2.0