3 Replies Latest reply on Dec 9, 2011 11:01 AM by Radoslav Husar

    save image in webapp/resources

    Richard Schubert Newbie



      we want to save in image in our war as "webapp/resources/file.gif". But default file root is "C:\jboss-as-7.0.2.Final\bin\" where we don't want our file to be saved.

      How can be save in webapp folder?


      BufferedImage img = new BufferedImage(p.getWidth(),p.getHeight(), BufferedImage.TYPE_INT_RGB);
      ImageIO.write(img, "GIF", new File(Dateiname + ".gif"));
        • 1. Re: save image in webapp/resources
          Radoslav Husar Master

          Rather then answering the question you shoudl revise why you want to do that. This looks like a bad idea to me. If the images are permanent (which is unlikely since you want to store it with the app) then store it elsewhere in the filesystem or database. If the images are temporary store them in the memory (eg cache).

          • 2. Re: save image in webapp/resources
            Richard Schubert Newbie

            I tried storing the image in local filesystem. But i then couldn't access image in xhtml. I guess this is because all content must be placed in deployed war (which does not contain stuff from local filesystem).


            Concerning storing them in memory: How do I do that? Do you mean storing image as byte[]? If so I'm struggling with finding tags that accept byte[]. I found one in seam tag library, but I don't know if I can install seam tag library with jboss7 and maven.

            • 3. Re: save image in webapp/resources
              Radoslav Husar Master

              Well, its a fact that serving static images via Java is slower than letting Apache HTTPd serve them.


              Thats why I think a better approach is to store images on the filesystem where HTTPd just serves them statically. In your Java side all you need is to send in your respose <img src="/static/images.png" /> and the context static just let the apache to handle and not pass all the way to Java. You will also have to handle deletion from the FS, authorization might become little bit more complicated. Anyway, depends on your use case :-)