• Post Reply Bookmark Topic Watch Topic
  • New Topic

jsp:forward problem

 
Dharmesh Chheda
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Arun Boraiah
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have to close the out put stream by calling out.close()before fowarding to new jsp. Hope this will help you.
-arun
 
Dharmesh Chheda
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Dharmesh Chheda
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!