2 Replies Latest reply on Feb 18, 2007 3:47 AM by Jeroen Wenting

    IllegalStateException problem on running jboss

    Kevin Liu Newbie

      Hi,everybody
      I am using jboss 4.0.5 GA, it generates the following error when i tried to test a ckcodeimage.jsp:


      14:20:15,796 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
      java.lang.IllegalStateException: getOutputStream() has already been called for this response
      at org.apache.catalina.connector.Response.getWriter(Response.java:599)
      at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
      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:182)
      at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
      at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
      at org.apache.jsp.jsp.ckcodeimage_jsp._jspService(ckcodeimage_jsp.java:133)
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:334)
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
      at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      at org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
      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.Http11AprProcessor.process(Http11AprProcessor.java:833)
      at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:639)
      at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1285)
      at java.lang.Thread.run(Thread.java:595)



      ckcodeimage.jsp is the following:
      <%@ page contentType="image/jpeg; charset=GBK" import="java.awt.*,java.awt.image.*,java.util.*,javax.imageio.*" %>
      <%!
      Color getRandColor(int fc,int bc){//??????????
       Random random = new Random();
       if(fc>255) fc=255;
       if(bc>255) bc=255;
       int r=fc+random.nextInt(bc-fc);
       int g=fc+random.nextInt(bc-fc);
       int b=fc+random.nextInt(bc-fc);
       return new Color(r,g,b);
       }
      %>
      <%
      //???????
      response.setHeader("Pragma","No-cache");
      response.setHeader("Cache-Control","no-cache");
      response.setDateHeader("Expires", 0);
      
      // ????????
      int width=60, height=20;
      BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
      
      // ???????
      Graphics g = image.getGraphics();
      
      //?????
      Random random = new Random();
      
      // ?????
      g.setColor(getRandColor(200,250));
      g.fillRect(0, 0, width, height);
      
      //????
      g.setFont(new Font("Times New Roman",Font.PLAIN,18));
      
      //???
      //g.setColor(new Color());
      //g.drawRect(0,0,width-1,height-1);
      
      
      // ????155???????????????????????
      g.setColor(getRandColor(160,200));
      for (int i=0;i<155;i++)
      {
       int x = random.nextInt(width);
       int y = random.nextInt(height);
       int xl = random.nextInt(12);
       int yl = random.nextInt(12);
       g.drawLine(x,y,x+xl,y+yl);
      }
      
      // ?????????(4???)
      //String rand = request.getParameter("rand");
      //rand = rand.substring(0,rand.indexOf("."));
      String sRand="";
      for (int i=0;i<4;i++){
       String rand=String.valueOf(random.nextInt(10));
       sRand+=rand;
       // ??????????
       g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));//???????????????????????????????
       g.drawString(rand,13*i+6,16);
      }
      
      // ??????SESSION
      session.setAttribute("rand",sRand);
      
      
      // ????
      g.dispose();
      
      // ???????
      ServletOutputStream output = response.getOutputStream();
      ImageIO.write(image, "JPEG", output);
      
      %>