0 Replies Latest reply on Jun 26, 2007 10:45 AM by Joao Mello

    Image into a tab

    Joao Mello Newbie

      If have this

      public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      Socket s = null;
      ServletOutputStream out = res.getOutputStream();
      Enumeration keys = null;
      String key = null;
      String value = null;
      String user = "";
      String query = "";
      String cmd = "200";
      /*
      keys = req.getParameterNames();
      do
      {
      if(!keys.hasMoreElements())
      break;
      key = (String)keys.nextElement();
      value = req.getParameter(key);
      if(key.equals("user"))
      user = value;
      else
      if(key.equals("query"))
      query = value;
      else
      if(key.equals("cmd"))
      cmd = value;
      } while(true);
      */

      user = "web";
      query = "3802";
      cmd = "200";
      if(!user.equals("")) {
      try {
      s = new Socket(dbserver, dbport);
      getImage(s, user, query, cmd, res);
      s.close();
      } catch(IOException e) {
      out.println("Class adwebster.hAPImage: Unable to open socket to " + dbserver + " on port " + dbport + ".");
      log("Class adwebster.hAPImage: Unable to open socket to " + dbserver + " on port " + dbport + ".", e);
      }
      } else {
      res.setContentType("text/html");
      out.println("");
      out.println("");
      out.close();
      return;
      }
      }

      public void getImage(Socket s, String user, String query, String cmd, HttpServletResponse res)
      throws IOException {
      String line = null;
      String temp = null;
      String sendString = null;
      int indx = 0;
      BufferedInputStream in = new BufferedInputStream(new DataInputStream(s.getInputStream()));
      BufferedReader inAscii = new BufferedReader(new InputStreamReader(s.getInputStream()));
      OutputStream sOut = s.getOutputStream();
      DataOutputStream dOut = new DataOutputStream(sOut);
      ServletOutputStream out = res.getOutputStream();
      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      byte b[] = new byte[10240];
      user = user.replace('+', ' ');
      query = query.replace('+', ' ');
      sendString = new String("200|" + user + "|FILENAME|" + query + "|VIEWFILEJPEG|st\n");
      dOut.writeBytes(sendString);
      user = user.replace(' ', '+');
      query = query.replace(' ', '+');

      Image img = Toolkit.getDefaultToolkit().createImage(baos.toByteArray());

      do {
      int bytes = in.read(b);
      if(bytes != -1) {
      baos.write(b, 0, bytes);
      } else {
      b = baos.toByteArray();
      res.setContentType("image/jpeg");
      out.write(b, 0, b.length);
      in.close();
      sOut.close();
      dOut.close();
      out.close();
      return;
      }
      } while(true);
      }

      The output is an image. How do I put the result into <rich:tab> inside a or a . When I run this open into a new full window.

      Thanks