Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect problem!help me

 
Val Lee
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First,I want to show "hello" on browser,
Next,redirect to www.yahoo.com
but,the browser shows only "hello",don't redirect to www.yahoo.com.
If del out.flush(),browser can redirect to www.yahoo.com.But don't show "hello".
who can tell me, why?
thanks.
 
suresh thallam
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
replace your code with this one
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException { PrintWriter out = response.getWriter(); out.println("<html><body>Hello!</body><script>window.location.href='http://www.yahoo.com'</script></html>");
Please let me know, if still have problems
Thanks
Suresh
 
Kyle Tang
Ranch Hand
Posts: 78
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can't call "flush" before calling sendRedirect.
as a general rule, flush means your response is over, nothing more. no more changes in status code, headers, or response-body. Otherwise, IllegalStateException. Tomcat doesn't give your that exception, because it is lenient. It just ignores the output after flush.
Kyle
 
Val Lee
Ranch Hand
Posts: 41
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks!
 
Maha Annadurai
Ranch Hand
Posts: 87
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This line of code
response.sendRedirect("http://www.yahoo.com");
after out.flush() does produce the IllegalStateException in Tomcat also. Check your log file (C:\jakarta-tomcat-4.0.3\logs\localhost_log_date.log) The exception is logged in there.
Since the response is already commited , there is no way to send this exception to browser again. This is the reason you do not see any exception displayed in browser.
If you try to make a try ... catch block then you can realize that the IllegalStateException is reaised indeed.

Regards,
Maha Anna
[ November 30, 2002: Message edited by: Maha Annadurai ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic