aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes sendRedirect problem!help me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sendRedirect problem!help me" Watch "sendRedirect problem!help me" New topic
Author

sendRedirect problem!help me

Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41

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.


Val SCJP2 1.2<br />====>SCJD
suresh thallam
Greenhorn

Joined: Sep 08, 2002
Posts: 2
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

Joined: Aug 22, 2002
Posts: 78
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


Kyle Tang<br />SCJP 91<br />SCWCD 96<br />SCBCD 95
Val Lee
Ranch Hand

Joined: Nov 27, 2001
Posts: 41
Thanks!
Maha Annadurai
Ranch Hand

Joined: Oct 27, 2002
Posts: 87
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
 
subject: sendRedirect problem!help me