Forums Register Login

jsp:forward problem

+Pie Number of slices to send: Send
hello
i have a jsp:forward problem
the scenario is as follows.
i have three JSP files..
In the First File say "FirstPage.jsp" i am including one jsp file say "Included.jsp". and in the included jsp file i am forwarding to some other jsp file say "forwarded.jsp" but i am getting an error IllegalStateException
the error i am getting is as follows.
java.lang.IllegalStateException: ERROR: Cannot forward. Writer or Stream already obtained.
i am working on WebSphere 3.5... please reply soon me really stuck
+Pie Number of slices to send: Send
you have to close the out put stream by calling out.close()before fowarding to new jsp. Hope this will help you.
-arun
+Pie Number of slices to send: Send
hi arun .. i tried that .. but the control is not getting transferred .. see i have pasted my files here
First file:

INCLUDED FILE:


FORWARDED FILE

now i am getting the error
ServletInstan X Uncaught service() exception thrown by servlet {0}: {1}
[ January 28, 2002: Message edited by: Dharmesh Chheda ]
+Pie Number of slices to send: Send
You can't forward after the response has been committed.
Possibly see this thread in Servlets forum first, but esentially 'include' lets you concatenate pages together, and 'forward' makes responding the problem of another JSP (or source).
Your code is saying this:
"I want to send some data to the user (ie from the first page)" and this data gets cached in an output buffer. Then you say "I want to send more data, it can be found in the INCLUDED file". Then it goes off to the included file and adds this data to the buffer as well.
THEN you say "I don't want to reply to the client here, I want the data sent to the client to come from the FORWARDED file".
At this stage, it tries to clear the buffer. If the buffer hasn't been filled or flushed yet, this is possible and ONLY the FORWARDED data will be sent.
If any data from the buffer has already been sent, you are 'committed' to sending the first part and it won't send ANY of the second part.
Dave
+Pie Number of slices to send: Send
Thanks david .. that was really helpful to me .
but then is there any other option for the thing which i am mentioning below
i have a web application which uses around 20 JSP files.. on each page i have to check for the session expiration .. so i have a jsp file which checks for the session. i include that session jsp file in all my pages to check for the session.. if the session has expired then i forward the control to some relogin page .. thats what i am trying to do ... waiting for your reply
+Pie Number of slices to send: Send
Have a look at some articles on the MVC (or Model 2) pattern for pages.
You have a Servlet that receives the request but never sends any data directly to the client. The advantage is that the Servlet implements the security and decides what the user sees.
Hence:

Note: this is heavy pseudocode!
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1173 times.
Similar Threads
Exception while using JSF Facelets "jsp:forward is not bound."
Converting ResultSet String to ArrayList
JSP Forward page param problem with iPlanet
Javascript code inside JSP (error in flushing)
Error ???? import EJB class in JSP
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 14:25:27.