Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Regarding sendRedirect

 
Karne Reddy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
The behaviour of sendRedirect is not according to SPEC or HFSJ.
In the servlet( or jsp), i wrote into printwriter object and commited
the response by using flush method. Then after that if i am using sendRedirect("/one.jsp"), Its not throwing IllegalStateException.

???
And my another quest is HFSJ is saying that
if we use sendRedirect("/one.jsp"), the containe will look for one.jsp in
/doc-root/ (i.e /doc-root/one.jsp) . But its not happening.
???
I am using Tomcat 5.0

--------------
SCJP1.4 91%
 
Gaurav Gambhir
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer1

You cannot call sendRedirect() after writing to response.You will get IllegalStateException if you try to invoke it after the response has already been committed.
By committed means response has been sent it means you cannot write the response and then call sendRedirect().


since You commited the response by using flush method it means, that the IllegalStateException() is not visible on the client side, as the response has been already sent.

----------------
Answer2

If you are using the sendRedirect() where relative URL start with forward slash, then yes you have to specify the webapp root directory also, i.e web application name, in order to make it work, yes in HFSJ its wrong.
 
Karne Reddy
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Gambhir,

Ur reply helped me.

So we should not blindly follow or study the HFSJ. We sholud experiment
the things.

Thanx once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic