Problem to output image using ServletOutputStream

Hallo everybody! Can anybody help me? I try to output image (jpeg) using ServletOutputStream. First I upload jpeg image to server disassemble it to binary data and save to database binary data, image length, and image type. Then I try to output image.
Here the code:
response.reset();
response.setContentType(strContentType);
ServletOutputStream sos=response.getOutputStream();
sos.write(buf,0,bflen);
sos.close();
variable buf is array of byte with binary data
bflen is image length
strContentType it image type (image/pjpeg)
I use JRun server 3.1
I tried to save an image file:
FileOutputStream fos = new FileOutputStream("test_logo.jpg");
fos.write(buf,0,bflen);
fos.close();
And I got an jpeg file.

I've done the exact same thing... almost. I have a
servlet that sends a jpeg file to an applet for
processing. Anyway, I did two things differently.
First I used the write(byte[]) rather than
write(byte[], int offset, int length). If you're
going to send the whole array anyway, don't bother
with the other parameters.
Second, I call flush() on the output stream before I
close it. I have a feeling this is why. Remember,
web connections are connectionless. You don't know if
the data was send or received. I assume what is
happening is that you try to send the data then close
the connection right away and the data may not get to
the destination.
Here's what I have. I don't think the content type
really matters but I know multipart/form-data is
binary.
response.setContentType("multipart/form-data");
response.getOutputStream().write(image.data);
response.getOutputStream().flush();
response.getOutputStream().close();
I'll try it. But I have problem to call getOutputStream() method. It produce IllegalStateExeption. I think that because implicit getWriter() method calls. (I use JSP)
Do you know how to reset somehow response to have ability to call getOutputStream()?

Similar Messages

  • Problems reading BMP images using ReadImage function

    I am trying to load BMP images using the IMAQ Vision ReadImage function (VB6). The images load as monochrome images.
    I use the CWIMAQViewer1.Pallette as a parameter in the command.
    Note: The images load fine when using Vision Assistant or other image viewing software.
    Any ideas?
    Thanks!

    Sorry. Wrong forum. I'll repost on Machine Vision forum.

  • Output Image using OutputStream

    All
    There's a need to display a graph created by jFreeChart:
    ChartUtilities.writeChartAsPNG(out, chart, width, height)It should display in a new window after pressing a Plot-Button in the application window.
    How would one do this?
    Basically I need to set the content type to 'image/png' and then I need a OutputStream which I can write to.
    Where to begin? Is this possible at all? Alternatively one could put the graph to a file and then use that ;-(
    Thanks a lot for any help

    Well, not many suggestions eh?
    I did this one (based on another post in the forum).
    Just for those interested ;-)
        public String getPlotUrl() {
            log.debug("Creating a temporary Graph-File");
            ServletContext context = ( ServletContext ) getExternalContext().getContext();
            String realPath = context.getRealPath("/resources");
            File file = null;
            try {
                file = File.createTempFile( this.getHttpSession().getId(), ".png", new File( realPath ) );
            } catch (IOException e1) {
                e1.printStackTrace();
            file.deleteOnExit(  );
            OutputStream outs = null;
            try {
                outs = new BufferedOutputStream( new FileOutputStream( file ) );
            } catch (FileNotFoundException e1) {
                e1.printStackTrace();
            ChartGenerator cg = new ChartGenerator(this.getRequestBean());
            cg.createChart();
            try {
                cg.printChart( outs );
            } catch (IOException e) {
                e.printStackTrace();
            try {
                outs.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            setPlotUrl( "/resources/" + file.getName());
            log.debug("Temp. File: " + this.plotUrl);
            return this.plotUrl;
        }

  • Problem printing output statements using c:out tag

    Hello All,
    I am new to JSTL. For some reason <c:out >is not printlng "HelloWorld!" instead it is printing "{hello}"
    <c:set var="hello" value="Hello World!"/>
    <p/>
    <c:out value="${hello}"/>
    Here is how I have setup my jstl
    1.I downloaded jakarta-taglibs-standard-current.zip from apache.
    Copy jakarta-taglibs/standard-1.0.3/tld/c.tld to my WEB/INF/tlds directory.
    2.Copied all the JAR files in jakarta-taglibs/standard-1.0.3/lib to myWEB-INF/lib directory.
    Added the entry shown below to your WEB-INF/web.xml deployment descriptor.
    <taglib>
    <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
    </taglib>
    Can anyone please help me out fixing this problem?

    hmm not sure.. sorry about the last code... the reason mine is the way it is is because I am including it locally incase the user doesn't have a connection to the internet just the intranet. as follows.
    <taglib>
            <taglib-uri>/WEB-INF/c.tld</taglib-uri>
            <taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
        </taglib>I don't know why yours is not working. Hopefully someone who is more knowledgable then me on the subject will have some ideas.

  • Problem in processing image using IMAQ

    I want to do image processing (filtering, thresholding and skeletonizing) on my acquired image. Unfortunately, the program that I made cannot run. When I try to execute it, the error message: incompatible image size appears. Anybody can point out what's wrong with my program? Attached is the VI that I made. Really appreciate your help.
    Attachments:
    Image_Acquisition.vi ‏71 KB

    Check where you are getting your image from. You should be taking the image from the IMAQ Get Image.VI. The way your code is currently set up, you are processing a non-existant image. LabVIEW will run any subVI as soon as all of it's inputs are satisfied. Your processing is set up to start just after you create the image buffer, rather than waiting until after you fill it.

  • Problem in displaying images using JLabel in Netbeans

    hi all,
    i am trying to display an image on JLabel in Netbeans.The image is visible in the design view but not displayed in the runtime.Can anyone help me out with suggestions???

    Duplicate - answer here http://forum.java.sun.com/thread.jspa?threadID=5153605&messageID=9578626#9578626

  • Problems with output using html2fo function

    Hello,
    I have a problem with output when using html2fo function.
    My sample xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <RTECODE>
    <![CDATA[
    <table border="1">
    <tr>
    <td>row 1, cell 1</td>
    <td>row 1, cell 2</td>
    </tr>
    <tr>
    <td>row 2, cell 1</td>
    <td>row 2, cell 2</td>
    </tr>
    </table>
    ]]>
    </RTECODE>
    Can anybody explain why the rtf template output is different in pdf, rtf, excel ? It looks ok only in pdf.
    Thanks in advance.

    Check these
    http://docs.oracle.com/cd/E23943_01/bi.1111/e22254/create_rtf_tmpl.htm#CHDCEEIJ
    https://blogs.oracle.com/xmlpublisher/entry/html_in_xml_support
    If helps mark
    Edited by: Srini VEERAVALLI on Feb 25, 2013 10:04 AM

  • Problem grabbing image using libdc on ubuntu 12.10,build on new firewire-stack unibrain fire-i camera

    i am new to digital camera softwares.i am using unibrain fire-i camera on ubuntu 12.10 .firewire stack is new,i am using libdc1394 for grabbing images.i try to execute the example program grab-gray-image.the output image file is not giving result what i expected . i try to grab a human face image.i am adding this as an attachment. the camera parameters are as follows.
    Brightness:
    RC MC (active is: AUTO) AC (active is: AUTO)
    min: 128 max 383
    current value is: 304
    Exposure:
    RC MC (active is: AUTO) AC (active is: AUTO)
    min: 0 max 511
    current value is: 511
    Sharpness:
    RC MC (active is: MAN)
    min: 0 max 255
    current value is: 80
    White Balance:
    RC MC (active is: AUTO) AC (active is: AUTO)
    min: 0 max 255
    B/U value: 95 R/V value: 87
    Hue:
    NOT AVAILABLE
    Saturation:
    RC MC (active is: MAN)
    min: 0 max 255
    current value is: 90
    Gamma:
    RC MC (active is: MAN)
    min: 0 max 1
    current value is: 1
    Shutter:
    RC MC (active is: MAN)
    min: 0 max 7
    current value is: 6
    Gain:
    RC MC (active is: MAN)
    min: 0 max 255
    current value is: 87
    Iris:
    NOT AVAILABLE
    Focus:
    NOT AVAILABLE
    Temperature:
    NOT AVAILABLE
    Trigger:
    NOT AVAILABLE
    Trigger Delay:
    NOT AVAILABLE
    White Shading:
    NOT AVAILABLE
    Frame Rate:
    NOT AVAILABLE
    Zoom:
    NOT AVAILABLE
    Pan:
    NOT AVAILABLE
    Tilt:
    NOT AVAILABLE
    Optical Filter:
    NOT AVAILABLE
    Capture Size:
    NOT AVAILABLE
    Capture Quality:
    NOT AVAILABLE
    i am unable to identify the problem .please anyone help me.
    Thanks in advance.

    Excellent Blog. Thank You
    Small clarification on Step **6) Oracle Home Directory, ...a) Resize the Root Partition**
    Ubuntu 11.10 has Gparted available as a Ubuntu software download, DONT use that while trying the above step, instead download the ISO file from http://sourceforge.net/projects/gparted/files/gparted-live-stable/ gparted-live-0.12.0-5.iso (124.6 MB)
    Burn that ISO file on a Blank DVD, reboot the Ubuntu , during startup select Boot from DVD Option if not already selected. this will take to Boot Menu Options of Gparted Live then select the first menu option, and this allows to do further action such as Re-sizing .
    and once you have chosen and executed step a) . do NOT run step b) also that is "Setup External Storage"
    I hope this minor clarification can avoid some confusion
    Regards
    Madhusudhan Rao
    Edited by: MadhusudhanRao on Mar 24, 2012 11:30 PM

  • Problem in creating 1 image using differnt images

    Dear Fellows I want to create an image by using different images in byte array format. Images may be transparent or normal images. I want final result in byte array. I am using the following technique which is working fine but the problem with this technique is that it takes too much time to create an image. This is because I am using MediaTraker. If I delete the code of MediaTracker then program have undeterministic behavior i.e, sometimes it create the final image properly and sometimes nothing is displayed in final image.
    I need some help from you. If anyone of you know the technique to draw image using different images without using mediaTracker kindly let me know.
    Early replies will be appreciated
    // here is the sample code which i m using for creating image
    byte[] backgroundImage= // read 800 X 600 image from disk and convert it in to byte array
    byte[] image1 = // read 200 X 200 image from disk and convert it in to byte array
    byte[] transparentImage // read 300 X 300 transparent image from disk and convert it in to byte array
    Image img=null;
    Frame frame =new Frame();
    frame.addNotify();
    //creating BufferedImage object to store Final image
    BufferedImage requiredImage= new BufferedImage(800,600,BufferedImage.SCALE_SMOOTH);
    //get Graphics of BufferedImage created above
    Graphics2D g=(Graphics2D) requiredImage.getGraphics();
    ///// begin draw back ground image
    img=Toolkit.getDefaultToolkit().createImage(backgroundImage);
    try
    MediaTracker mt = new MediaTracker(frame);
    mt.addImage(img, 0); // adds image with ID 0
    mt.waitForID(0);
    }catch(Exception myex)
    myex.printStackTrace();
    //draw background starting from x=0, y=0 with 800 X 600 dimentions
    g.drawImage(img,0,0,800,600,null);
    ////////// end draw background image
    ////////// begin draw image1
    img=Toolkit.getDefaultToolkit().createImage(image1);
    try
    MediaTracker mt = new MediaTracker(frame);
    mt.addImage(img, 0); // adds image with ID 0
    mt.waitForID(0);
    }catch(Exception myex)
    myex.printStackTrace();
    //draw image1 starting from x=10, y=10 with 200 X 200 dimentions
    g.drawImage(img,10,10,200,200,null);
    //////////// end draw image1
    //////begin transparentImage
    img=Toolkit.getDefaultToolkit().createImage(backData);
    try
    MediaTracker mt = new MediaTracker(frame);
    mt.addImage(img, 0); // adds image with ID 0
    mt.waitForID(0);
    }catch(Exception myex)
    myex.printStackTrace();
    //draw transparentImage starting from x=400, y=0 with 300 X 300 dimentions
    g.drawImage(img,400,0,300,300,null);
    ///end draw transparent image
    byte []finalResult = //convert requiredImage into byte array;
    you can mail me the solution on my email address [email protected]
    thanks with best regards
    and waiting for someone to reply
    kamran zameer

    is there anyone on this forum to help me??????
    regards,
    kamran zameer

  • Problem in creating client side PDF with image using flex and AlivePD

    I need a favor I am creating client side PDF with image using flex and AlivePDF for a web based application. Images have been generated on that pdf but it is creating problem for large size images as half of the image disappeared from that pdf.I am taking the image inside a canvas . How do i control my images so that they come fit on that pdf file for any image size that i take.
    Thanks in advance
    Atishay

    I am having a similar and more serious problem. It takes a
    long time to execute, but even attaching a small image balloons the
    pdf to 6MB plus. After a few images it gets up to 20MB. These are
    100k jpeg files being attached. The resulting PDF is too large to
    email or process effectively. Does anyone know how to reduce
    size/processing?

  • I am importing videos from my canon sl1 to my macbook when i use iphoto is says "iPhoto cannot import your photos because there was a problem downloading an image." and when i use image capture it says "An error occured while importing. The item 'MVI_1040

    I am importing videos from my canon sl1 to my macbook air when i use iphoto is says "iPhoto cannot import your photos because there was a problem downloading an image." and when i use image capture it says "An error occured while importing. The item ‘MVI_1040'' Thanks in advance

    Can you access the images on the phone with Image Capture (in the Applications Folder) ?

  • Search for images using Keywords Problem.

    1) In LR4, Search for images using Keywords (click on arrow next to Keyword).
    2) Select image, export to PS6, save as Tif.
    3) Tif retains all Keywords when it appears in LR
    4) Despite that, image does not show up in the same 'Search for images using Keywords'.
    Can anyone help with this, it is frustrating me!

    V. 4.1
    Thanks, I will try, but it seems to be an inconsistent problem.
    Simon Fletcher
    Simon Fletcher Photography
    Woody's Nest
    Newton of Kinkell
    by Conon Bridge
    Ross-shire
    Scotland
    UK  IV7 8AS
    Tel: 01 349 864 830
    Web: www.simonfletcherphotography.co.uk
    Work:
    The Glass Scribe
    Tel: 01 349 867 088
    Email: [email protected]
    Web: www.glassscribe.com

  • Problems acquiring and saving multiple camera images using a switch with GigE cameras

    Hi Folks,
    We are having an issue with connecting 6 GigE cameras via an Ethernet switch. We can acquire and store individual cameras but once we increase the number of cameras we end up with jumpy avi files.
    Each camera has been physically labelled and attached to the switch, so camera 1 is attached to port 1, which then corresponds to Cam1 in MAX. When recording multiple files what appears to happen is that the avi file from cam1 actually has images from multiple cameras, as if cam1 is being renamed/allocated on each frmae and each time a different camera is allocated. How can we fix this?
    We are new to this so any help or advice would be much appreciated.
    Thanks in advance,
    Cathy
    Attachments:
    Camerad.png ‏60 KB
    Camera.vi ‏91 KB

    I think your problem is caused by using the same image name on each instance of Imaq create. "Grab and Save to AVI Acq" being the string you are using. I am pretty sure If you make each image name unique you wont get image referance problems.
    Senior Software Engineer
    www.Adansor.com

  • Print Images using FOP

    Can we print images using FOP by taking it from the database ? Iam using the FOP and outputing to a PDF. However, I have an image that I would like to print. The image is stored in the database as a BLOB. How can I print this image in the PDF document ?
    (b) Alternatively, if this is not possible, do we need to move the image to a physical file system and use <img src> and print ? If so, how can we move the image to the file system ? I found only UTL_FILE can do this ? But Iam not sure if it can work properly for Image file. When I tested this using utl_file, my image file got corrupted.

    Hi there, from what type of device are you trying to print the images from e.g. a smartphone/tablet or a PC/laptop?
    Best
    If my reply helped you, feel free to click on the Kudos button (hover over the "thumbs up").
    If my reply solved your problem please click on the Accepted Solution button so other Forum users may benefit from viewing the post.
    I am an HP employee.

  • Having problems copying an image

    I'm having problems copying an image. The Image comes from my jar file and I'm trying to copy it to my hard drive. The problem is that it seems to add extra characters at the beggining and maybe at the end as well. I used a Hex Editor to compare the contents.
    Anyway I was wondering if anyone could offer suggestions.
    My code is listed below in case that helps.
    "in" is an InputStream, "content" is a byte array, and "out" is an OutputStream
    try {
       in = getClass().getResourceAsStream("LoveGameSm.gif");
       content = new byte[in.available()];
       out = new ObjectOutputStream(new FileOutputStream("Tmp.gif"));
       in.read(content);
       out.write(content);
       out.flush();
       in.close();
       out.close();
    catch(Exception e)  {
       e.printStackTrace();
       return null;
    }

    The problem is in the use of ObjectOutputStream... this does not work the way you think it does. It is used to serialize an object to an output stream. A serialized object is just the on-disk representation of a Java object. So, you are getting a serialized copy of a byte array, which is why there are extra characters.
    Instead, just leave off the ObjectOutputStream stuff, and write to the FileOutputStream. Better yet, wrap it in a BufferedOutputStream to increase performance.

Maybe you are looking for

  • Wls 6.0sp1, xerces 1.1

    I'm in the process of upgrading to weblogic 6.0sp1 from 5.1. My app uses xerces 1.1 for all xml parsing. My original configuration was jbuilder 4.0, weblogic 5.1, jdk1.2.2 and xerces 1.1. This configuration worked and all xml parsed fine. After upgra

  • Can the new Mac Mini boot Snow Leopard from an external hard drive?

    I currently boot my 2009 Mac Mini from a FW800 external drive with 10.6.8. If I just plug my external drive into a new 2011 Mac Mini, will it boot into Snow Leopard if I set it as the startup disk or will I get a kernel panic?

  • Canon MP 600, G5 dual 2.0, OS 10.4.8

    I have spent at least 20 hours trying to resolve this to date. I am meticulous with all of my Macs. I removed the MP600 drivers, reinstalled combo 4.8 update for ppc on the G5, restarted the G5 twice, ran everything in the disk utility with no errors

  • ClassCastException launching Applet under JRE 7u21

    I'm working on a signed Applet that will no longer start under version 7u21 of the JRE, and I've been able to isolate the problem to the Java Plugin's cache. If I disable Temporary files in the Java Control Panel, then everything's file. If I enable

  • Image.cpp error

    When I try to print the labview panel & diagram on my new canpn pixma iP1000 printer I get the following message. I am using LV6.0 "image.cpp error" in line 11035. Please contact ni.com. Anyone can help!