Servlets & images

hi
i'm using apache server
my servlet class files r in /home/test102/servlet directory
in the browser i give http://<ipadd>:8080/servlet/<filename>
so whr do i store images and how to retrieve them and access in client side
pls help me out

It's OK, I've managed to find it. for those of you looking for it it is the obviously named 'HTML root directory' in project properties/paths.
null

Similar Messages

  • Saving image in MySQL database

    Best groupmember,
    I want to save my images in a MySQL database. After storing that in the database I want to be able to present it using a servlet. Something like this (show image with id=4 from the database):
    <img src="/servlet/image?id=4">
    Would be happy to be guided to example code or tutorials about how to store images in a MySQL database using Java.
    -- Best of Times
    Peter Lauri

    Ok for storing images you'll have to use the type BLOB (=Binary Large Object) for the rest i would suggest that you take a look at the jdbc-documentation....
    this might help... :p
    http://java.sun.com/j2se/1.5.0/docs/api/java/sql/ResultSet.html#getBlob(int)

  • I want to display BLOB image in JSP Using  html tags IMG src=

    GoodAfternoon Sir/Madom
    I Have got the image from oracle database but want to display BLOB image using <IMG src="" > Html tags in JSP page . If it is possible than please give some ideas or
    Send me sample codes for display image.
    This code is ok and working no problem here Please send me code How to display using html tag from oracle in JSP page.
    <%@ page import="java.sql.*" %>
    <%@ page import="java.io.*" %>
    <%@ page import="javax.swing.ImageIcon;" %>
          <%
            out.print("hiiiiiii") ;
                // declare a connection by using Connection interface
                Connection connection = null;
                /* Create string of connection url within specified format with machine
                   name, port number and database name. Here machine name id localhost
                   and database name is student. */
                String connectionURL = "jdbc:oracle:thin:@localhost:1521:orcl";
                /*declare a resultSet that works as a table resulted by execute a specified
                   sql query. */
                ResultSet rs = null;
                // Declare statement.
                PreparedStatement psmnt = null;
                  // declare InputStream object to store binary stream of given image.
                   InputStream sImage;
                try {
                    // Load JDBC driver "com.mysql.jdbc.Driver"
                    Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
                        /* Create a connection by using getConnection() method that takes
                        parameters of string type connection url, user name and password to
                        connect to database. */
                    connection = DriverManager.getConnection(connectionURL, "scott", "root");
                        /* prepareStatement() is used for create statement object that is
                    used for sending sql statements to the specified database. */
                    psmnt = connection.prepareStatement("SELECT image FROM img WHERE id = ?");
                    psmnt.setString(1, "10");
                    rs = psmnt.executeQuery();
                    if(rs.next()) {
                          byte[] bytearray = new byte[1048576];
                          int size=0;
                          sImage = rs.getBinaryStream(1);
                        //response.reset();
                          response.setContentType("image/jpeg");
                          while((size=sImage.read(bytearray))!= -1 ){
                response.getOutputStream().write(bytearray,0,size);
                catch(Exception ex){
                        out.println("error :"+ex);
               finally {
                    // close all the connections.
                    rs.close();
                    psmnt.close();
                    connection.close();
         %>
         Thanks

    I have done exactly that in one of my applications.
    I have extracted the image from the database as a byte array, and displayed it using a servlet.
    Here is the method in the servlet which does the displaying:
    (since I'm writing one byte at a time, it's probably not terribly efficient but it works)
         private void sendImage(byte[] bytes, HttpServletRequest request, HttpServletResponse response) throws IOException {
              ServletOutputStream sout = response.getOutputStream();
              for(int n = 0; n < bytes.length; n++) {
                   sout.write(bytes[n]);
              sout.flush();
              sout.close();
         }Then in my JSP, I use this:
    <img src="/path-to-servlet/image.jpg"/>
    The name of the image to display is in the URL as well as the path to the servlet. The servlet will therefore need to extract the image name from the url and call the database.

  • Fatal bug with shared JDBC Session Persistence

    We are attempting to launch a three-tier site with two clusters, one at the
              web layer (JSP/servlet/images) and a separate cluster at the app server
              layer (EJBs). We are running WebLogic server 4.5.1 Service Pack 8 on Solaris
              2.7. In production we use Solaris JDK 1.2.1.04, and in development we use
              JavaSoft JDK 1.2.2. We are able to duplicate this problem with both JDKs. We
              are using the WebLogic kona/oracle driver for session persistence because
              the Oracle JDBC driver would not work for this purpose - we are using the
              Oracle OCI driver for our EJB persistence in a separate pool in the app
              server cluster.
              We attempted to configure our web cluster to work with in-memory session
              replication. We found the performance of the WebLogic proxy to be abysmal -
              causing a 5x to 10x performance degredation over shared JDBC persistence. We
              were running the proxy on WebLogic, which we were advised would be slow. Its
              performance is beyond slow, it is completely unusable and should NEVER be a
              recommended or even supported configuration. We do not wish to purchase
              separate licenses for iPlanet, refuse to run IIS in a production setting,
              and cannot use Apache until WebLogic 5.1, so we are stuck with shared JDBC
              persistence until we can upgrade to 5.1.
              Using JDBC session persistence with a shared persistent store amongst all
              the clustered web servers results in our users getting brand-new sessions
              populated with data from OTHER USERS' SESSIONS. This is very easy to
              replicate using the provided test JSP and java class. This behavior results
              in new users coming to the site and finding themselves logged in as other
              users.
              The test.jsp file simply accesses the session, prints out some information,
              and then adds a few values to the session. The JSP prints out the value of
              session.isNew(), the session's ID, and the number of values in the session
              space. If you hit this jsp with a new browser window, the session should be
              new, and the number of values should be zero.
              The test Java class hits a URL with this test.jsp file repeatedly, and
              checks to make sure that the session is empty. It keeps a counter of the
              number of hits which resulted in non-empty sessions and the total number of
              hits. Because this java class does not maintain cookie data of any kind and
              merely opens new HTTP connections, it should always receive a brand-new,
              non-empty session.
              When we set the JDBC session persistence property
              weblogic.httpd.session.persistentStoreShared=true and run the test, we see
              periodically see the test.jsp file receiving a brand-new (session.isNew() =
              true), yet non-empty (session.getValueNames().length != 0) session. This is
              extremely bad behavior and makes the shared JDBC session persistence setting
              worthless. We were able to duplicate this behavior with both a single server
              and multiple servers in a cluster.
              If we set weblogic.httpd.session.persistentStoreShared=false, then this test
              works fine. This also means that we cannot cluster web servers.
              To run the test, simply start a WebLogic instance using the provided
              properties file, put the jsp in the document-root somewhere, and then run
              SessionTest.java, providing the URL of the test JSP as the only command-line
              argument. You will need to modify the properties file to have the proper
              database settings and document-root. The java class will display a running
              tally of the number of hits, and the number of hits that result in
              non-empty, illegal sessions, with a total at the end.
              So, we are now in a position where we are completely unable to launch our
              site in a clustered, no-single-point-of-failure configuration. Obviously,
              clustering was one of the main reasons to choose WebLogic, and we are
              extremely distressed that we are unable to get this configuration to work.
              Any help would be appreciated.
              [web.standalone.properties]
              [SessionTest.java]
              [test.jsp]
              

    I hope this is not too far fetched, but we are expieriencing a similar
              problem with jms (messages are mixed up between queues). This happens only
              if we are using message persistence in an oracle db (everything works ok
              when we are not using persistent messages). Could it be that there is a
              serious bug in the jdbc code/oracle driver code or connection handling
              (regarding multi threading)? This would explain that, whenever you use
              persistence with oracle databases, messages/sessions (or other) are mixed
              up.
              - Falk
              "Grant Kushida" <[email protected]> wrote in message
              news:[email protected]...
              > We are attempting to launch a three-tier site with two clusters, one at
              the
              > web layer (JSP/servlet/images) and a separate cluster at the app server
              > layer (EJBs). We are running WebLogic server 4.5.1 Service Pack 8 on
              Solaris
              > 2.7. In production we use Solaris JDK 1.2.1.04, and in development we use
              > JavaSoft JDK 1.2.2. We are able to duplicate this problem with both JDKs.
              We
              > are using the WebLogic kona/oracle driver for session persistence because
              > the Oracle JDBC driver would not work for this purpose - we are using the
              > Oracle OCI driver for our EJB persistence in a separate pool in the app
              > server cluster.
              >
              > We attempted to configure our web cluster to work with in-memory session
              > replication. We found the performance of the WebLogic proxy to be
              abysmal -
              > causing a 5x to 10x performance degredation over shared JDBC persistence.
              We
              > were running the proxy on WebLogic, which we were advised would be slow.
              Its
              > performance is beyond slow, it is completely unusable and should NEVER be
              a
              > recommended or even supported configuration. We do not wish to purchase
              > separate licenses for iPlanet, refuse to run IIS in a production setting,
              > and cannot use Apache until WebLogic 5.1, so we are stuck with shared JDBC
              > persistence until we can upgrade to 5.1.
              >
              > Using JDBC session persistence with a shared persistent store amongst all
              > the clustered web servers results in our users getting brand-new sessions
              > populated with data from OTHER USERS' SESSIONS. This is very easy to
              > replicate using the provided test JSP and java class. This behavior
              results
              > in new users coming to the site and finding themselves logged in as other
              > users.
              >
              > The test.jsp file simply accesses the session, prints out some
              information,
              > and then adds a few values to the session. The JSP prints out the value of
              > session.isNew(), the session's ID, and the number of values in the session
              > space. If you hit this jsp with a new browser window, the session should
              be
              > new, and the number of values should be zero.
              >
              > The test Java class hits a URL with this test.jsp file repeatedly, and
              > checks to make sure that the session is empty. It keeps a counter of the
              > number of hits which resulted in non-empty sessions and the total number
              of
              > hits. Because this java class does not maintain cookie data of any kind
              and
              > merely opens new HTTP connections, it should always receive a brand-new,
              > non-empty session.
              >
              > When we set the JDBC session persistence property
              > weblogic.httpd.session.persistentStoreShared=true and run the test, we see
              > periodically see the test.jsp file receiving a brand-new (session.isNew()
              =
              > true), yet non-empty (session.getValueNames().length != 0) session. This
              is
              > extremely bad behavior and makes the shared JDBC session persistence
              setting
              > worthless. We were able to duplicate this behavior with both a single
              server
              > and multiple servers in a cluster.
              >
              > If we set weblogic.httpd.session.persistentStoreShared=false, then this
              test
              > works fine. This also means that we cannot cluster web servers.
              >
              > To run the test, simply start a WebLogic instance using the provided
              > properties file, put the jsp in the document-root somewhere, and then run
              > SessionTest.java, providing the URL of the test JSP as the only
              command-line
              > argument. You will need to modify the properties file to have the proper
              > database settings and document-root. The java class will display a running
              > tally of the number of hits, and the number of hits that result in
              > non-empty, illegal sessions, with a total at the end.
              >
              > So, we are now in a position where we are completely unable to launch our
              > site in a clustered, no-single-point-of-failure configuration. Obviously,
              > clustering was one of the main reasons to choose WebLogic, and we are
              > extremely distressed that we are unable to get this configuration to work.
              > Any help would be appreciated.
              >
              >
              >
              >
              

  • Uploading an image to a servlet with out  html form

    Hello,
    I had a look around the forum and could not find an answer to my question.
    I am trying to unload an image that is in a byte array to a servlet. the image is on the mobile phone. the mobile phone does not have html form to upload the picture.
    Is there any other way of uploading instead of using html form to invoke the servlet. It is just the connection bit that is confusing me. When the servlet is invoked then it can open an inputstream and take in the image.
    I hope this is clear and that some one else has done it.
    thanks
    martin

    search here and/or search google for "send byte array to servlet"
    it's certainly easy to find as far as i can tell
    first google result:
    http://forum.java.sun.com/thread.jspa?messageID=10173137&tstart=0

  • Problem with displaying BLOB images on JSP page using a servlet

    hi. I have a big problem with displaying BLOB images using JSP. I have a servlet that connects to the oracle database, gets a BLOB image , reads it, and then displays it using a BinaryStream. The problem is , this works only when i directly call that servlet, that is http://localhost:8080/ImageServlet. It doesn't work when i try to use that servlet to display my image on my JSP page (my JSP page displays only a broken-image icon ) I tried several coding approaches with my servlet (used both Blob and BLOB objects), and they work just fine as long as i display images explicitly using only the servlet.
    Here's what i use : ORACLE 10g XE , Eclipse 3.1.2, Tomcat 5.5.16 , JDK 1.5
    here is one of my image servlet's working versions (the essential part of it) :
                   BLOB blob=null;
              rset=st.executeQuery("SELECT * FROM IMAGES WHERE ID=1");
              while (rset.next())
                   blob=((OracleResultSet)rset).getBLOB(2);
              response.reset();
              response.setContentType("image/jpeg");
              response.addHeader("Content-Disposition","filename=42.jpeg");
                    ServletOutputStream ostr=response.getOutputStream();
                   InputStream istr=blob.getBinaryStream(1L);
                    int size=blob.getBufferSize();
              int len=-1;
                    byte[] buff = new byte[size];
                         while ((len=istr.read( buff ))!=-1 ) {
                   ostr.write(buff,0,len);
             response.flushBuffer();
             ostr.close(); and my JSP page code :
    <img src="/ImageServlet" border="0"  > If you could just tell me what i'm doing wrong here , or if you could show me your own solutions to that problem , i would be very greatful ,cos i'm realy stuck here , and i'm rather pressed for time too. Hope someone can help.

    I turns out that it wasn't that big of a problem after all. All i had to do was to take the above code and place it into another JSP page instead of into a servlet like i did before. Then i just used that page as a source for my IMG tag in my first JSP. It works perfectly well. Why this doesn't work for servlets i still don't know, but it's not a problem form me anymore . Ofcourse if someone knows the answer , go ahead and write. I would still appriceatte it.
    here's the magic tag : <img src="ImageJSP.jsp" border="0"  > enjoy : )

  • Print images created on the fly by a servlet

    Please, look at it... my tiff image doesn't print in my browser (IE6).
    Could somone tell me why !????
    // Method of a "Page" class
    public void write (OutputStream out) {
                // Reading of the tiff file (this.tempFile is a valid File)
         PlanarImage image    = JAI.create("fileload", this.tempFile.getCanonicalPath ());
                /*   // Test : the writed file is a valid tiff file --> the reading is OK !
                 *   File outFile = new File ("c:\\temp\\JLdsWeb\\Test.tif");
                 *   RenderedOp op = JAI.create("filestore", image, outFile.getCanonicalPath (), "tiff");
         // Writing of the tiff file in the received OutputStream
                JAI.create("encode", image, out, this.FORMAT_NAME, null);
    // my 1st JSP :page.jsp (to call the 2nd JSP witch have an other content type)
    <%@page
    contentType="text/html"
    language="java"
    errorPage="errorpage.jsp"
    import="com.damaris.ldsweb.*,com.damaris.data.*,com.damaris.page.*,java.util.*"
    %>
    <html>
    <head></head>
    <body>
    <IMG src=<%=request.getContextPath()%>image.jsp>
    </body>
    </html>
    // my 2nd JSP
    <%@page
    language="java"
    errorPage="errorpage.jsp"
    import="com.damaris.ldsweb.*,com.damaris.data.*,com.damaris.page.*,java.util.*"
    %>
    <html>
    <head>
    <%
        // pageToPrint is an instance of the class "Page" (getContentType ( ) give the String "image/tiff")
        response.setContentType(pageToPrint.getContentType ( ));
    %>
    </head>
    <body>
    <%
        ServletOutputStream bOut = response.getOutputStream();
        pageToPrint.write (bOut);
    %>
    </body>
    </html>

    You can get the Servlet to write an image out by changing the content type of the response object to "image/jpeg" and write the bytes of the image out down a ServletOutputStream you create from the response object.
    You must change the content type before you write anything to the response object. The servlet can only produce the image.
    I did it once but I've lost my code and am now trying to recreate it (I changed it to having a server app do the image processing and writing it to a socket which the servlet read the bytes from and wrote them to the ServletOutputStream but now want the servlet to do the processing).

  • Image seems not loading in servlet running in tomcat 4 ... (win xp)

    This servlet basically takes a images file do some scaling then send out as outputstream.
    BUT the image dun since to load ... i keep getting a -1 for the width n height of the image .... seems that image cant load in tomcat....
    Is it something wrong wif my code or is there a bug in tomcat....
    Can someone help thanks
    This is the servlet code:
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.image.*;
    public class ImageOperater extends HttpServlet
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException
    { System.out.println("Start of post");
    OutputStream out = null;
    try{
    out = res.getOutputStream();
    catch(Exception e)
    e.printStackTrace();
    System.out.println("Start of imageprocessing");
    //image processing
    Image img = Toolkit.getDefaultToolkit().getImage("images/peppers.png");
    ImageFilter imf = new CropImageFilter(0,0,200,200);
    ImageProducer ip = new FilteredImageSource(img.getSource(),imf);
    img = Toolkit.getDefaultToolkit().createImage(ip);
    img =img.getScaledInstance(500,-1,Image.SCALE_AREA_AVERAGING);
    //image processing finish
    //check if the image is fully loaded
    System.out.println("Start of image loading");
    MediaTracker mediaTracker = new MediaTracker(new Container());
    mediaTracker.addImage(img, 0);
    try{
    mediaTracker.waitForID(0);
    System.out.println(mediaTracker.checkAll());
    System.out.println("thread sleep");
    Thread.sleep(1000);
    catch(Exception e)
    e.printStackTrace();
    try{
    mediaTracker.waitForID(0);
    System.out.println(mediaTracker.checkAll());
    System.out.println("thread sleep");
    Thread.sleep(1000);
    catch(Exception e)
    e.printStackTrace();
    //image fully loaded
    System.out.println("Start of buffered image ");
    System.out.println("width"+img.getWidth(null)+" Height "+img.getHeight(null));
    //preparing the buffered image to be send
    BufferedImage bimg = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
    Graphics gr = bimg.getGraphics();
    gr.drawImage(img, 0, 0, null);
    gr.dispose();
    //finished preparing
    //ig = Toolkit.getDefaultToolkit().createImage(bimg.getSource());
    System.out.println("Start of sending");
    //send out to client
    try{
    ImageIO.write((RenderedImage)bimg,"png",new File("c:\\test.png"));
    ImageIO.write((RenderedImage)bimg,"png",out);
    catch(Exception e)
    e.printStackTrace();
    try{
    out.flush();
    out.close();
    catch(Exception e)
    e.printStackTrace();
    System.out.println("post ended");
    but if the same code is put into an applet it works ... thw getWidth() and getHeight() returns the correct value:
    Image img = Toolkit.getDefaultToolkit().getImage("images/peppers.png");
    ImageFilter imf = new CropImageFilter(0,0,200,200);
    ImageProducer ip = new FilteredImageSource(img.getSource(),imf);
    img = Toolkit.getDefaultToolkit().createImage(ip);
    img =img.getScaledInstance(500,-1,Image.SCALE_AREA_AVERAGING);
    //image processing finish
    //check if the image is fully loaded
    System.out.println("Start of image loading");
    MediaTracker mediaTracker = new MediaTracker(new Container());
    mediaTracker.addImage(img, 0);
    try{
    mediaTracker.waitForID(0);
    System.out.println(mediaTracker.checkAll());
    System.out.println("thread sleep");
    Thread.sleep(1000);
    catch(Exception e)
    e.printStackTrace();
    try{
    mediaTracker.waitForID(0);
    System.out.println(mediaTracker.checkAll());
    System.out.println("thread sleep");
    Thread.sleep(1000);
    catch(Exception e)
    e.printStackTrace();
    //image fully loaded
    System.out.println("Start of buffered image ");
    System.out.println("width"+img.getWidth(null)+" Height "+img.getHeight(null));
    //preparing the buffered image to be send
    BufferedImage bimg = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_INT_RGB);
    Graphics gr = bimg.getGraphics();
    gr.drawImage(img, 0, 0, null);
    gr.dispose();
    //finished preparing
    //ig = Toolkit.getDefaultToolkit().createImage(bimg.getSource());
    System.out.println("Start of sending");
    //send out to client
    try{
    ImageIO.write((RenderedImage)bimg,"png",new File("c:\\test.png"));

    hi ganttan
    first you have to make sure your server is running xwindow. in most cases a linux/apache server does not run it by default. then there is a much simpler approach of scaling images with a servlet:
    Iterator readers = ImageIO.getImageReadersByFormatName("gif");
    ImageReader reader = (ImageReader)readers.next();
    ImageInputStream iis = ImageIO.createImageInputStream(new File(path));
    reader.setInput(iis, true);
    ImageReadParam param = reader.getDefaultReadParam();
    param.setSourceRenderSize(new Dimension(width, height));
    BufferedImage thumbnail = reader.read(0, param);
    ImageIO.write(thumbnail, "gif", response.getOutputStream());
    however this does not work for jpeg images. use setSourceSampling() instead of setSourceRenderSize() in this case but unfortunately it's limited and you can not scale to any size.

  • Dynamic images in a Servlet with WL6.1

    Hi,
              I try to create a BufferedImage in a Servlet:
              BufferedImage img = new BufferedImage(320,200,
              BufferedImage.TYPE_INT_RGB);
              I get an UnsatisfiedLinkError to the log. The servlet works fine on
              Tomcat.
              The platform is Solaris 8 with Weblogic 6.1. The libawt.so is included
              in the CLASSPATH. The creation of the image works fine, if I run it
              from command line with the same JRE.
              regards, EK
              the log:
              <7.10.2002 16:04:57 EEST> <Error> <HTTP>
              <[WebAppServletContext(7518429,testwl61
              ,/testwl61)] Servlet failed with Exception
              java.lang.UnsatisfiedLinkError: exception occurred in JNI_OnLoad
              at java.lang.ClassLoader$NativeLibrary.load(Native Method)
              at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1382)
              at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1298)
              at java.lang.Runtime.loadLibrary0(Runtime.java:749)
              at java.lang.System.loadLibrary(System.java:820)
              at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:53)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.awt.image.ColorModel.loadLibraries(ColorModel.java:155)
              at java.awt.image.ColorModel.<clinit>(ColorModel.java:163)
              at java.awt.image.BufferedImage.<clinit>(BufferedImage.java:203)
              at com.testwl61.DrawServlet.doGet(DrawServlet.java:34)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
              pl.java:265)
              at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
              pl.java:200)
              at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
              rvletContext.java:2495)
              at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
              pl.java:2204)
              at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
              at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
              >
              

    Hi,
    Please post to an asp.net forum....if possible include a link to your website with your question.
    this forum is for questions about IEAK and GPO for system administrators of domain networks....
    tip... use response.end I/o response flush....
    view... the page-source from IE (View-source) or use the Find tool on the IE Developer tool to inspect the scr value of img tags and the base href value (if used)...
    the optimal load time for web pages is considered to be 3 seconds...
    consider reducing the number and size of images, and external stylesheets and libraries on your web pages. (www.webpagetests.org)
    Rob^_^

  • Display image in Servlet

    Hi everyone,
    I have a servlet and I would like to display an image on it, the image is already saved in the server in a folder. My current solution is to save the image to the client machine first then display. I feel it is not a good way.
    Do we have any other ways to do it ?
    Thank you very much for your suggestion.
    Regards
    Ryzin.

    My current solution is to save the image to the client machine first then display. How have you done it? This is technically impossible without asking permissions and knowing where the client have chosen to store it. Something says me that you're running the server as well as the client at the same PC in your development environment and that you're expecting that you can also write to client's file system in the real world, while the server is actually located at the another end of the network. Well, this is actually not true, that would be a big security hole, a server which unaskingly write files to the client's file system.
    Anyway, you can also just output <img src> pointing to another servlet which on it's turn streams the images to the client. Here is a good example:
    http://balusc.blogspot.com/2007/04/imageservlet.html

  • How can i pass more than 1 param to servlet to show blob image

    Hi
    my servlet expects 2 param to SELECt an image from a blob column
    public class ImageBlobServlet extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=windows-1252";
    public void init(ServletConfig config) throws ServletException {
    super.init(config);
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException,
    IOException {
    response.setContentType(CONTENT_TYPE);
    String ImageId = request.getParameter("id");
    String TipImg = request.getParameter("tip");
    OutputStream os = response.getOutputStream();
    Connection conn = null;
    try {
    Context ctx;
    ctx = new InitialContext();
    DataSource ds = (DataSource)ctx.lookup("java:/comp/env/jdbc/rhDS");
    conn = ds.getConnection();
    PreparedStatement statement = conn.prepareStatement("select FIT from " +
    "RHH_FOTOS IMG " +
    "where IMG.IDASSO = ? and IMG.TIM_COA = ?");
    statement.setInt(1, new Integer(ImageId));
    statement.setString(2, TipImg);
    To display the image i tried to use:
    <af:image id="ot1"
    *source="/imageblobservlet?id=#{bindings.Con.inputValue}?tip=#{"EMP"}"*
    shortDesc="Foto"/>
    but i receive all content in the get of first param.
    String ImageId = request.getParameter("id");
    How can i pass one more then 1 param in EL.
    Thanks in advance

    Hello,
    seems to me you're using wrong separator for the second param into your URL:
    <af:image id="ot1" source="/imageblobservlet?id=#{bindings.Con.inputValue}
    tip=#{"EMP"}" shortDesc="Foto"/>
    I think it should be:
    <af:image id="ot1" source="/imageblobservlet?id=#{bindings.Con.inputValue}
    tip=#{"EMP"}" shortDesc="Foto"/>
    Jack

  • Problem while encoding JPEG image from JFrame paintComponent in a servlet

    Hello!
    I m developing webapplication in which I made one servlet that calls JFrame developed by me, and then encoding into JPEG image to send response on client browser. I m working on NetBeans 5.5 and the same code runs well. But my hosting server is Linux and I m getting the following error:
    java.awt.HeadlessException:
    No X11 DISPLAY variable was set, but this program performed an operation which requires it.
         java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
         java.awt.Window.<init>(Window.java:406)
         java.awt.Frame.<init>(Frame.java:402)
         java.awt.Frame.<init>(Frame.java:367)
         javax.swing.JFrame.<init>(JFrame.java:163)
         pinkConfigBeans.pinkInfo.pinkModel.pinkChartsLib.PinkChartFrame.<init>(PinkChartFrame.java:36)
         pinkConfigBeans.pinkController.showLastDayRevenueChart.processRequest(showLastDayRevenueChart.java:77)
         pinkConfigBeans.pinkController.showLastDayRevenueChart.doGet(showLastDayRevenueChart.java:107)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.
    I m building the application in NetBeans and when runs then it runs well, even while browsing from LAN. But when I place the web folder creted under buil directory of NetBeans in the Tomcat on Linux, then it gives above error.
    Under given is the servlet code raising exception
    response.setContentType("image/jpeg"); // Assign correct content-type
    ServletOutputStream out = response.getOutputStream();
    /* TODO GUI output on JFrame */
    PinkChartFrame pinkChartFrame;
    pinkChartFrame = new PinkChartFrame(ssnGUIAttrInfo.getXjFrame(), ssnGUIAttrInfo.getYjFrame(), headingText, xCordText, yCordText, totalRevenueDataList);
    pinkChartFrame.setTitle("[::]AMS MIS[::] Monthly Revenue Chart");
    pinkChartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    //pinkChartFrame.setVisible(true);
    //pinkChartFrame.plotDataGUI();
    int width = 760;
    int height = 460;
    try {
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    pinkChartFrame.pinkChartJPanel.paintComponent(g2);
    JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
    encoder.encode(image);
    } catch (ImageFormatException ex) {
    ex.printStackTrace();
    response.sendRedirect("index.jsp");
    } catch (IOException ex) {
    ex.printStackTrace();
    response.sendRedirect("index.jsp");
    out.flush();
    Do resolve anybody!
    Edited by: pinkVag on Oct 15, 2007 10:19 PM

    >
    I m developing webapplication in which I made one servlet that calls JFrame developed by me, and then encoding into JPEG image to send response on client browser. I m working on NetBeans 5.5 and the same code runs well. But my hosting server is Linux and I m getting the following error:
    java.awt.HeadlessException: >That makes sense. It is saying that you cannot open a JFrame in an environment (the server) that does not support GUIs!
    To make this so it will work on the server, it will need to be recoded so that it uses the command line only - no GUI.
    What is it exactly that PinkChartFrame is generated an image of? What does it do? (OK probably 'generate a chart') But what APIs does it use (JFreeChart or such)?

  • How to update image files in web pages generated by servlet without redeploying

    HI,
    I have a servlet which generates html pages with images. Those images changes
    as they are graph generated regularly. They are placed in s directory where the
    application is deployed. It is necessary because I have made some security constraints
    for the location of those files. However it seems that when I deploy my application
    on WLS all files contained in the application directory are cached, and when for
    ex. I delete some of them they are still appear in generated html pages. only
    Redeployment of application updates the state of those files.
    Is there a way to make the application to be aware of any changes in images files
    and to load updated ones??
    i would be interested in a situatioin like with default WLS servelt (DefaultWeb
    Application) where any new files are seen as soon as they are placed in Default
    WebApplication directory.
    Is there a way to periodically redeploy application from CLI?
    thx in advance
    Michal

    889096 wrote:
    Hello!
    In SQL Developer when we run htp package then we see the generated code in OWA Output, But how to invoke or show the webpage by Oracle tools/plsql program.
    and
    Without copying the code and save it to textfile.html and open it with browser.
    I heard it is possible by configuring Apache server.
    Please give me brief details, as i am beginner with ORACLE 10g
    And
    If you are using the htp package, you are presumably developing for an application server? Can the people who set that up not help you with your development environment?
    Setup is too complicated to cover here. Check out the Oracle HTTP Server documentation on oracle's documentation pages.
    Briefly, you need to install Oracle HTTP Server and then configure a data access desciptor to connect to your database.
    How to see the generated code in "QUEST TOAD"? I am not able to see OWA output in TOADYou will have to ask this question in a Toad forum.

  • Not possible to get image & text in a servlet

    Hi
    i want to display a image and below to that wnat to display a text.But text is not displaying.Please refer the following code.
    package com.Test;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.NamingException;
    public class imagetry1 extends HttpServlet{
       public void doGet(HttpServletRequest req, HttpServletResponse res)
          throws ServletException, IOException{
         PrintWriter out = res.getWriter();
          try{
             // out.println("<h1> Drapes <hr> </h1>");
             FileInputStream fis = new FileInputStream("c:/hi/world.jpg");
             BufferedInputStream bis = new BufferedInputStream(fis);
             byte[] bytes = new byte[bis.available()];
             res.setContentType("image/jpeg");
             OutputStream os = res.getOutputStream();
             bis.read(bytes);
             os.write(bytes);
             String s1 = "Drapes";
             byte[] b1 = s1.getBytes();
             os.write(b1);
             res.setContentType("text/html" );
             out.println("<h1> Drapes <hr> </h1>");
          catch(IOException e){
    }

    Oh no.
    * JSP/Servlet outputs HTML.
    * Images in HTML are to be displayed using <img> tag.
    * The 'src' attribute of the <img> tag expects a valid URL (yes, URL!!) to the image.
    Clear?
    OK, if you use a local file system path of the server machine instead of a public URL to the image in the 'src' attribute, then it is certainly not going to work. The HTML is been sent from the server machine to the client machine. The HTML is been parsed and evaluated at the client machine. Any URL's will be invoked to the server again, but any local file system paths will be invoked on the local file system of the client machine.
    To stream images from the non-public file system of the server machine to the HTTP response, you need to create a servlet which does the simple task: read an InputStream from the file and write it to OutputStream of the response. You can find here an example: [http://balusc.blogspot.com/2007/04/imageservlet.html].

  • Setting attributes of image stored in byte array in servlet

    Hi,
    I am using a servlet to stream image (GIF) to the browser.
    Image is accessed by browser using the img tag. src attribute points to the servlet which send the image stream.
    Servlet has the image as the array of bytes. It simply write these bytes on the response object's output stream. It does not use any encoder.
    I get the image on the browser. But when I try to see the properties of the image I don't see the type of image. I also don't see the created time, modified time and size of the image. When I do Save As on this image it tries to save it as BMP instead of GIF. Also when I do the print preview I don't see the image in the preview window. When I try to print the web page, it prints everything except this image. I get small cross(image missing) on the printed page.
    I would like to know why the image attributes on browser go missing and why can't I print the image?
    I would like to add that I am getting the image as the array of bytes from a different application on which I do not have control.
    Thanks.

    Hi,
    I am using a servlet to stream image (GIF) to the browser.
    Image is accessed by browser using the img tag. src attribute points to the servlet which send the image stream.
    Servlet has the image as the array of bytes. It simply write these bytes on the response object's output stream. It does not use any encoder.
    I get the image on the browser. But when I try to see the properties of the image I don't see the type of image. I also don't see the created time, modified time and size of the image. When I do Save As on this image it tries to save it as BMP instead of GIF. Also when I do the print preview I don't see the image in the preview window. When I try to print the web page, it prints everything except this image. I get small cross(image missing) on the printed page.
    I would like to know why the image attributes on browser go missing and why can't I print the image?
    I would like to add that I am getting the image as the array of bytes from a different application on which I do not have control.
    Thanks.

Maybe you are looking for

  • Different Apple IDs for iTunes and iCloud

    As a legacy from MobileMe,  I have one Apple ID for iTunes (around 10 years old) that has all of my purchases, and another for iCloud (created later as a requirement of MobileMe) that has all the email, syncing, etc.  Apparently now I can't use Famil

  • Slow PDF files in mail

    Every time I get a CAD file in PDF format on my new Mac Book Pro e-mail, it blocks the cursor and take a long time to respond. Any suggestions? System: -Retina -2.7 Intel i7 -16 GB 1600  Mhz  DDR3 -Intel ND Graphics 4000 512MB -OS X 10.8.2

  • Storage Space Server

    If the space of the windows storage space server is full, is it possible to setup another windows storage space server and combine the new one to original storage pool?

  • Linked Servers - Sql server 2005 to connect to Oracle 11g using ldap.ora instead of tnsnames.ora

    We have a SQL Server 2005 64bit box that needs a linked server created to Oracle 11g 64bit box. I have all the Oracle client software installed and can successfully connect to the Oracle database using SQL+ on the SQL Server 2005 64bit box. When I cr

  • Iphone 5 is requesting me to change my login to 16 characters

    iphone 5 is requesting me to change my 4 character login password to a 16 character password.  Is this legit?  Typing a 16 digit password each time I want to use the phone is a real pain?