• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Regarding sendRedirect

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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%
 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
machines help you to do more, but experience less. Experience this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic