| Author |
Help please: forwarding a request in a jsp
|
Jim So
Greenhorn
Joined: Mar 18, 2009
Posts: 28
|
|
Hi, If you forward a request in a jsp to another page, then can you still call out.println()? Or will you get a runtime error?
Also if you do
out.println("1");
RequestDispatcher view = request.getRequestDispatcher("secondJSP.jsp");
view.forward(request,response);
out.println("2");
======
second.jsp:
out.println("in second jsp");
What will be outputted to the client?
a) 1 in second jsp 2
b) 1
c) 2
d) in second jsp
e) runtime error
and if you get a runtime error, then at which point is is thrown?
If i didnt have the line out.println("2"); would it still output "1 in second jsp"?
|
 |
Naren Chivukula
Ranch Hand
Joined: Feb 03, 2004
Posts: 542
|
|
Based on my knowledge, I feel you get IllegalStateException as the reponse is already flushed by the time you dispatch it.
Cheers,
Naren
SCJP - 93%
SCDJWS - 86%
SCWCD - ?
|
Cheers,
Naren (SCJP, SCDJWS and SCWCD)
|
 |
vani venkat
Ranch Hand
Joined: Nov 21, 2006
Posts: 142
|
|
hi jim
i tried this example and got
is in second jsp
as output. however if you add out.flush(); in first jsp before getting request dispatcher and forward, only the contents written before forward happens are shown as output.
if out.flush is called abd then if you forward to another jsp, contents written in first jsp are shown as output and nothing after forward shows up on page.
however if you do forward (like in this example), response is cleared out and only the contents of second jsp are shown.
|
SCJP 1.4, SCWCD 1.5
|
 |
 |
|
|
subject: Help please: forwarding a request in a jsp
|
|
|