am getting IllegalStateException when iam using response.sendRedirect.I have not used response.flushBuffer() in that page. And i have caught the Exception also. I have tried and got 2 solutions also 1) response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location","/sivashakthi/general/editError.jsp?path="+request.getRequestURI()+"&message="+message); generally this is working fine but when iam using in place of sendRedirect where iam getting illegal it is not working nothing is making difference 2) changed the buffer size=12 its working fine but my superior needs sol by coding it seems. for coding i have to pass through url but sendRedirect is not working
any body plz help [ September 03, 2005: Message edited by: sai prasanna ]
It's tricky to use redirect within a JSP, because the page generates output, after which a redirect is no loger possible. It would be a better design to determine which action/path to take somewhere in a servlet or Java class, and then to do a forward or redirect from there to the appropriate JSP page.
sai, Make it very simple for yourself. After every call to response.sendRedirect, add a return statement.
If you must test the output stream after a redirect, make sure to add a return statement before closing your scriptlet tag. Otherwise the JSP compiler will may add println statements that will cause the IllegalStateException.
JSPs are best used for formatting your output. Servlets are better for handling control flow.