Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:forward

 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I need an immediate clarification. My jsp program uses a session. I want to redirect the page to a html page when the session times out. but when I give jsp:forward, it throws an exception saying that "cannot clear JspWriter buffer. Already written source ... " and it does not re direct the page.
Please help.
Thanks,
Prabhu.V.C
 
sanj singh
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prabhu
I guess the problem is with your buffer attribute of the page directive.Try increasing the buffer size of the current.
Regards
sanj
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if this is the case, but I remember a problem I had early on in my professional Servlet/JSP experience in which I could not forward a POST to a satic HTML page. A GET was OK...
 
Andrew Shafer
Ranch Hand
Posts: 338
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prabhu
As always, a little code goes a long way. People could give you a better answer if they know what your code looks like.
The jsp:forward is passing the request and response objects to the new page using the same method as the original request. As Tony said, static html files cannot handle POST requests. One work around is to rename the .html file to .jsp, this will give the same behavior for both GET or POST.
There might be another problem with your design. Http is based on requests from the client. You can't have the page change in real time because something expired on the server. The request to change must come from the client. I think commonly people use response.sendRedirect() on the next client request, after the session has expired. (You could do some funky stuff calculating when the session would expire and setting refresh headers, but the request is still really being generated from the client)
regards,
Andrew
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI,
Why not use some (lowly) javascript?
You could set a function in your page to count the time and when your limit is reached to redirect using:
location.href='newpage.html';
Here's an example you can use as a template.

Hope that helps,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everybody for your replies ....
I rectified the problem i had mentioned about. I had included a stylesheet prior to the <jsp:forward> being given. I dont know the cause of the problem, but when I shifted the <include> directive after the <jsp:forward> it is now working fine.
Thanks again.
If any ou U friends can enlighten me as to reason of the error, it would be very helpful.
Thanks,
Prabhu.V.C

------------------
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI Prabhu,
You got the solution because after a <jsp:include> you can't use <jsp:forward>, because the buffer flushes before processing the include.
If it were necessary to leave them in the order they were in before, then changing the <jsp:include> action for a <%@include %> directive would solve your problem.
Bye,

------------------
Terry Doyle
Sun Certified Programmer for Java 2 Platform
 
Prabhu Chandrasekaran
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks yet again for ur prompt replies.
Bye,
Prabhu.V.C

------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic