sandeep manglani
sandeep manglani

Reputation: 87

Problem in redirecting to a page

I'm developing a web application.

I've wrriten a jsp, servlet and a bean. On sucessful insertion of records into database I want to redirediect to a new page but response.sendredirect() reports an error.

The error

The server encountered an internal error () that prevented it from fulfilling this request.

Exception:

java.lang.IllegalStateException
    org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:435)
    javax.servlet.http.HttpServletResponseWrapper.sendRedirect(HttpServletResponseWrapper.java:126)
    allotmant.seatAllot.processRequest(seatAllot.java:104)
    allotmant.seatAllot.doGet(seatAllot.java:134)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)

Note: The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

What could be a possible solution?

Upvotes: 1

Views: 3373

Answers (2)

WhiteFang34
WhiteFang34

Reputation: 72039

Make sure that you're:

  1. Performing the redirect early enough in the page. If it's too late in the page then the response headers will have already been committed to the stream. It only buffers so many bytes before beginning to send to the client, typically 8k.
  2. Immediately stop processing the rest of the page once you do the sendRedirect(). For the same reason as #1 if you let the rest of the page render it can fill up the response buffer. Call return right after your sendRedirect() to end your servlet, JSP or the like.

Upvotes: 1

helios
helios

Reputation: 13841

I think you cannot send a redirect after commiting the headers of the response. When you redirect the header must contain the redirect action. But if you already sent some body content the headers are committed.

So maybe you are sending body content (or mannually commiting the headers) before the redirect.

Upvotes: 1

Related Questions