Forums Register Login

Redirecting to other Web Resource

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
hi Jaggi,
With Tomcat you won't get this exception, you must try it with other things than Tomcat.
I already read it in this forum once(somebody was at the same situation as you)...search in this forum.
He's giving us the slip! Quick! Grab this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 377 times.
Similar Threads
Which version of EJB?
Still have no results for SCEA 5 beta
Servlet Filtering doesnt work on iPlanet 6
Synchronization
JFRAME ERROR
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:46:50.