Problems in running web application in WebSphere 4.0

Discussions

Web tier: servlets, JSP, Web frameworks: Problems in running web application in WebSphere 4.0

  1. We are trying to deploy a web application in Websphere 4.0. The application
    gets deployed fine but at runtime it gives an error stating :


    java.lang.IllegalStateException: Writer already
    obtained
               at
    com.ibm.servlet.engine.srt.SRTServletResponse.getOutputStream(SRTServletResp
    onse.java:337)

               at
    com.ibm.servlet.engine.webapp.HttpServletResponseProxy.getOutputStream(HttpS
    ervletResponseProxy.java:98)


    We get this error for all the files (Servlet or JSP's) that open an
    outputstream, after or before doing an include in the request dispatcher
    interface.

    For Servlets this is the code snippet

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    {

    ServletOutputStream out;
    out = response.getOutputStream();
    out.println("<noscript>");
    out.println("<meta http-equiv='refresh' content='0;url="+
    System.getProperty("HTML") + "JScript.html'>");
    out.println("</noscript>");

    getServletContext().getRequestDispatcher(System.getProperty("FORWARDJSP")+"S
    tatusBar.jsp").include(request, response); // it

    fails at this line
    out.println("</body></html>");
    }

    similiarly if we have a code like this :

    public void doPost(HttpServletRequest request, HttpServletResponse response)
    {


    getServletContext().getRequestDispatcher(System.getProperty("FORWARDJSP")+"S
    tatusBar.jsp").include(request, response);
    ServletOutputStream out;
    out = response.getOutputStream(); // it fails here
    out.println("</body></html>");
    }

    the error in both the cases is :

    java.lang.IllegalStateException: Writer already
    obtained
               at
    com.ibm.servlet.engine.srt.SRTServletResponse.getOutputStream(SRTServletResp
    onse.java:337)

               at
    com.ibm.servlet.engine.webapp.HttpServletResponseProxy.getOutputStream(HttpS
    ervletResponseProxy.java:98)


    The same files work fine in weblogic.
    A quick response will be highly appreciated.
    Thanks in advance

    Bhootnath Singh
  2. This is actually the correct implementation. According to the Servlet 2.3 spec (I know WAS 4.0 only implements 2.2, but it's the same)

    IllegalStateException - if the getWriter method has been called on this response

    So, I'm wondering since your including a JSP page and JSPs intrinsically have access to the 'out' variable and the 'out' variable is a JspWriter object which is probably created from the reponse.getWriter() call, could the IllegalStateException be correct?