Results 1 to 5 of 5
  1. #1
    shaktish is offline Member
    Join Date
    Dec 2007
    Posts
    1
    Rep Power
    0

    Default how to display uploaded jpeg in jsp(its urgent)

    hi all,

    i am upload image(jpeg) using FormFile.........
    then i am trying to display it but it display the bytes only....
    my code is as below....

    jsp.

    <html:form action="/viewImage.do" method="post" enctype="multipart/form-data">

    <table cellpadding="0" cellspacing="0" border="0" summary="Image table">
    <tr>
    <td align="right">Image </td>
    <td align="left">
    <html:file property="image" />
    </td>
    </tr>
    <tr>
    <td align="center" colspan="2">
    <html:submit property="saveImage">Upload Image</html:submit>
    </td>
    </tr>
    </table>
    </html:form>
    ------------------------my action is

    public void disImage(ActionMapping mapping,
    ActionForm form, HttpServletRequest request,
    HttpServletResponse response) throws Exception {

    CompanyImageForm companyImageForm = (CompanyImageForm)form;
    FormFile myFile = companyImageForm.getImage();
    String contentType = myFile.getContentType();
    String fileName = myFile.getFileName();
    int fileSize = myFile.getFileSize();
    byte[] fileData = myFile.getFileData();
    InputStream in = new ByteArrayInputStream(fileData);
    BufferedImage image=javax.imageio.ImageIO.read(in);
    response.setContentType(contentType);
    OutputStream sos = response.getOutputStream();
    ImageIO.write(image,"jpeg",sos);
    }

    thanks,
    shaktish

  2. #2
    Join Date
    Jan 2009
    Posts
    1
    Rep Power
    0

    Default

    Hi I joined today only.

  3. #3
    Join Date
    Jan 2009
    Location
    Bangalore
    Posts
    4
    Rep Power
    0

    Default

    You need to user the image tag available

    <html:img alt="" src="img/modif.jpg" height="" />

    and you should be giving the image location for the attribute src

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Yes, you need to take the bytes from the JPEG file and stream them out to a file in a directory on your Web server. In your JSP, create an image tag pointing to the file you just created.

  5. #5
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default

    when you are uploading the image. you must know the uploaded path...
    right?
    and you know the file name also...
    then whats the prob dear?

Similar Threads

  1. displaying uploaded images on the browser
    By newton in forum Web Frameworks
    Replies: 3
    Last Post: 03-31-2011, 10:56 AM
  2. Hi, need some urgent help!
    By jdark in forum New To Java
    Replies: 2
    Last Post: 04-18-2008, 06:50 AM
  3. please help urgent
    By ananas7777 in forum AWT / Swing
    Replies: 2
    Last Post: 12-25-2007, 08:30 AM
  4. need urgent help...
    By SCS17 in forum New To Java
    Replies: 1
    Last Post: 11-13-2007, 07:52 AM
  5. Simplest way to read and display a jpeg image
    By Hasan in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •