Hello people!

I'm trying to retrieve an image of the mysql database, I am trying to
restore the image using servlet but I'm not very skilled with it ...
I code returns the following error:

java.lang.IllegalStateException: Committed
        at org.mortbay.jetty.Response.resetBuffer(Response.java:995)
        at org.mortbay.jetty.Response.reset(Response.java:938)
        at
br.com.google.server.FileUploadServlet.doGet(FileUploadServlet.java:
52)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:
487)
        at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:
362)
        at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:
216)
        at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:
181)
        at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:
729)
        at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:
405)
        at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
        at
org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:
49)
        at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:
152)
        at org.mortbay.jetty.Server.handle(Server.java:324)
        at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:
505)
        at org.mortbay.jetty.HttpConnection
$RequestHandler.headerComplete(HttpConnection.java:829)
        at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:513)
        at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
        at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
        at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:
395)
        at org.mortbay.thread.QueuedThreadPool
$PoolThread.run(QueuedThreadPool.java:488)
[WARN] 405 - GET /upload (127.0.0.1) 1462 bytes
   Request headers
      Host: 127.0.0.1:8888
      Connection: keep-alive
      User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/
535.11 (KHTML, like Gecko) Chrome/17.0.963.83 Safari/535.11
      Accept: */*
      Referer: 
http://127.0.0.1:8888/ProjetoImagem.html?gwt.codesvr=127.0.0.1:9997
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: pt-BR,pt;q=0.8,en-US;q=0.6,en;q=0.4
      Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
      Cookie: JSESSIONID=uibpkj9tbmhv
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1462


I will also post my class on the server side:

public class FileUploadServlet extends HttpServlet {

        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse
resp) throws ServletException, IOException {
                super.doGet(req, resp);

                 Connection conn = null;
                 Statement st = null;
                try
                {
                        Class.forName(AbstractDAO.DRIVER);
                        conn = DriverManager.getConnection(AbstractDAO.URL,
AbstractDAO.USUBD, AbstractDAO.SENHABD);

                        st = conn.createStatement();
                        ResultSet rs = st.executeQuery("SELECT IMAGEM FROM 
tbl_imagem where
CD_IMAGEM = 2");

                        String imgLen = "";

                        while(rs.next()){
                                imgLen = rs.getString(1);
                                System.out.println(imgLen.length());
                                int len = imgLen.length();
                                byte [] rb = new byte[len];
                                InputStream readImg = rs.getBinaryStream(1);
                                int index = readImg.read(rb, 0, len);
                                System.out.println("index 
------------------------" + index);
                                resp.reset();
                                resp.setContentType("image/jpg");
                                resp.getOutputStream().write(rb, 0, len);
                                resp.getOutputStream().flush();
                        }

                        st.close();
                        resp.getOutputStream().close();

                } catch (Exception e) {
                        e.printStackTrace();
                }
        }
}

to retrieve the client-side image I made as follows:

        Image image = new Image(GWT.getHostPageBaseURL() + "upload");
        rootPanel.add(image, 289, 138);
        image.setSize("200px", "200px");


Anyone know any solution for me to solve my problem or any tips that I
may be using?

Thank you!
Leonardo Terrão

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to