aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Redirecting to other Web Resource Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Redirecting to other Web Resource" Watch "Redirecting to other Web Resource" New topic
Author

Redirecting to other Web Resource

Jaggi Kunal
Ranch Hand

Joined: Jan 21, 2003
Posts: 45
An extract from Developing Java Servlets
“The sendRedirect(String) should be called before the response is committed otherwise an IllegalStateException will be thrown…”
I am using Tomcat 4.1.12.
Following is the code snippet :
public void doGet(HttpServletRequest req,HttpServletResponse response)throws ServletException,IOException
{
response.setContentType("text/html");
PrintWriter pw=response.getWriter();
pw.println("Sun ONE");
response.flushBuffer();
response.sendRedirect("http://localhost:8080/servlet/DefaultImageServlet");
pw.close();
}
-------------
Output (In the Browser window) :
Sun ONE
-------------
Now in this case, neither I get an exception not I am redirected to DefaultImageServlet.
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
Jaggi,
I just ran your code - the IllegalStateException is thrown... it is not displayed in the browser, but if you look in the Tomcat log you will see it.
Mark
Jaggi Kunal
Ranch Hand

Joined: Jan 21, 2003
Posts: 45
Hi Mark,
Where is the Tomcat log file stored. I know it may differ from your comp. to mine, but can you give me some rough idea.
Regards,
Kunal Jaggi
SCJP2
[ March 26, 2003: Message edited by: Jaggi Kunal ]
Mark Bensing
Ranch Hand

Joined: Mar 09, 2003
Posts: 40
Jaggi,
There is a logs directory under the directory where Tomcat is installed. There are several log files in that directory - the one you want to look at should be localhost_log.<date>.txt. For example, on my machine this is E:\Tomcat4.0\logs\localhost_log.2003-03-26.txt
Mark
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Redirecting to other Web Resource