Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Redirecting to other Web Resource

 
Jaggi Kunal
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic