Flks,

        Herez a stack trace in the tomcat environment ( Windows 2000 / J2SE
1.4.2_09 / Tomcat 5.5.12 ). Every request processed results in this trace.
However, the image gets rendered fine. Seems like the problem is because of
the new line characters in the JSP. If I compact the JSP to not have any new
line characters, this error doesn't occur. My question is that when the
content type is indicated as 'image/png', why are the new lines translated
to the out.write("\r\n");  statements in the servlet code ?

        PS: This JSP is deployed as part of a struts application, and for
certain reasons, I'd like to use an action-JSP combination to stream the
image instead of simple serlvet.

        JSP:
        ===========

        <%@ page session="false" contentType="image/png"
        
import="java.io.IOException,java.io.OutputStream,com.csg.chart.Chart,
java.util.HashMap"
        %>

        <%
                        // write the chart to the response as a image
stream.
                        Chart chart= (Chart)request.getAttribute("chart");
                        OutputStream outputStream=null;
                        try
                        {
                                outputStream = response.getOutputStream();
                                java.util.Map map = new java.util.HashMap();
                                chart.saveAsPNG(map, outputStream);
                        
                        }
                        catch (IOException ioe)
                        {
                                ioe.printStackTrace();
                        }

%>

        Servlet code for the JSP:
        =========================

        package org.apache.jsp.pages.factAnalysis;

        import javax.servlet.*;
        import javax.servlet.http.*;
        import javax.servlet.jsp.*;
        import java.io.IOException;
        import java.io.OutputStream;
        import com.csg.chart.Chart;
        import java.util.HashMap;

        public final class showchart_jsp extends
org.apache.jasper.runtime.HttpJspBase
            implements org.apache.jasper.runtime.JspSourceDependent {

          private static java.util.Vector _jspx_dependants;

          public java.util.List getDependants() {
            return _jspx_dependants;
          }

          public void _jspService(HttpServletRequest request,
HttpServletResponse response)
                throws java.io.IOException, ServletException {

            JspFactory _jspxFactory = null;
            PageContext pageContext = null;
            ServletContext application = null;
            ServletConfig config = null;
            JspWriter out = null;
            Object page = this;
            JspWriter _jspx_out = null;
            PageContext _jspx_page_context = null;


            try {
              _jspxFactory = JspFactory.getDefaultFactory();
              response.setContentType("image/src");
              pageContext = _jspxFactory.getPageContext(this, request,
response,
                                null, false, 8192, true);
              _jspx_page_context = pageContext;
              application = pageContext.getServletContext();
              config = pageContext.getServletConfig();
              out = pageContext.getOut();
              _jspx_out = out;

              out.write("\r\n");
              out.write("\r\n");

                        // write the chart to the response as a image
stream.
                        Chart chart= (Chart)request.getAttribute("chart");
                        OutputStream outputStream=null;
                        try
                        {
                                outputStream = response.getOutputStream();
                                java.util.Map map = new java.util.HashMap();
                                chart.saveAsPNG(map, outputStream);
                        
                        }
                        catch (IOException ioe)
                        {
                                ioe.printStackTrace();
                        }


            } catch (Throwable t) {
              if (!(t instanceof SkipPageException)){
                out = _jspx_out;
                if (out != null && out.getBufferSize() != 0)
                  out.clearBuffer();
                if (_jspx_page_context != null)
_jspx_page_context.handlePageException(t);
              }
            } finally {
              if (_jspxFactory != null)
_jspxFactory.releasePageContext(_jspx_page_context);
            }
          }
        }


        Trace:
        =====

        <log4j:event
logger="org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/cont
ributionmodeller].[jsp]" timestamp="1132574570398" level="ERROR"
thread="http-8080-Processor24">
        <log4j:message><![CDATA[Servlet.service() for servlet jsp threw
exception]]></log4j:message>
        <log4j:NDC><![CDATA[ipAddress=192.168.151.107
hostname=radhakrishnan-j]]></log4j:NDC>
        <log4j:throwable><![CDATA[java.lang.IllegalStateException:
getOutputStream() has already been called for this response
                at
org.apache.catalina.connector.Response.getWriter(Response.java:596)
                at
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:1
86)
                at
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
                at
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
                at
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:191)
                at
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFacto
ryImpl.java:115)
                at
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.j
ava:75)
                at
org.apache.jsp.pages.factAnalysis.showchart_jsp._jspService(org.apache.jsp.p
ages.factAnalysis.showchart_jsp:71)
                at
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
                at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:3
22)
                at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
                at
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
                at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:252)
                at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:173)
                at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.
java:672)
                at
org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDis
patcher.java:463)
                at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatch
er.java:398)
                at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher
.java:301)
                at
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:10
56)
                at
org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProces
sor.java:388)
                at
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:231)
                at
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
                at
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:397)
                at
javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
                at
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
                at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:252)
                at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:173)
                at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:213)
                at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
va:178)
                at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126
)
                at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105
)
                at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
:107)
                at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
                at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
                at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:744)
                at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.jav
a:527)
                at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWo
rkerThread.java:80)
                at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:684)
                at java.lang.Thread.run(Thread.java:534)
        ]]></log4j:throwable>
        </log4j:event>

Regards,
Radhakrishnan J
phone: +91-80-51368888 x 582
e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to