Results 1 to 6 of 6

Thread: How display a image on Servlet from a File Upload

  1. #1
    vijaykumardahiya is offline New Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    6

    Default How display a image on Servlet from a File Upload

    My requirement is I want to display a Image on Servlet from File Upload.
    But It not display on servlet,Its appear a downloaded form and downloaded on disk when click on save button.Other thing is that It not a .jpg form.that mean It does not open by photo gallery.that message show file format not supported by Photo Gallary.
    I also install I the Live HTTP headers 0.14 from Google in Firefox.
    I run the weblogic on Firefox and run that progarm but same issue persist.
    I also used Internet Browser,but problem are not solved.
    I already download comman-file upload-1.2.1.jar and comman-io-1.4 in lib folder and set this on classpath.
    Here my files:
    Home.html:
    Code:
    
    
    File
    UploadFile.java:
    Code:
    import java.io.*;
    import java.io.IOException;
    import java.util.Iterator;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import org.apache.commons.fileupload.DiskFileUpload;
    import org.apache.commons.fileupload.FileItem;
    import org.apache.commons.fileupload.FileItemFactory;
    import org.apache.commons.fileupload.FileUpload;
    import org.apache.commons.fileupload.FileUploadException;
    import javax.activation.DataSource;
    public class UploadFile extends HttpServlet {
    public void doPost(HttpServletRequest req,HttpServletResponse res)
    {
    try{
    FileUpload fup=new FileUpload();
    boolean isMultipart = FileUpload.isMultipartContent(req);
    // Create a new file upload handler
    System.out.println(isMultipart);
    DiskFileUpload upload = new DiskFileUpload();
    // Parse the request
    List items = upload.parseRequest(req);
    Iterator iter = items.iterator();
    while (iter.hasNext()) {
    FileItem item = (FileItem) iter.next();
    InputStream in=item.getInputStream();
    int len = req.getContentLength();
    System.out.println("Running Starting");
    System.out.println("*************");
    System.out.println("Length is: "+len); 
    System.out.println("+++++++++++");
    byte [] dataBytes = new byte[len]; 
    int index=in.read(dataBytes, 0, len);
    System.out.println("********");
    System.out.println("index"+index);
    System.out.println("+++++++++");
    // res.reset();
    res.setContentType("image/jpg");
    res.setHeader("Content-Disposition", "attachment; filename=\"image.jpg\"");
    System.out.println("One image writting");
    res.getOutputStream().write(dataBytes,0,len);
    res.getOutputStream().flush(); 
    System.out.println("Suceesfully send");
    }
    }
    catch(Exception e){System.out.println(e);}
    }
    }
    web.xml:
    Code:
    
    
    one
    UploadFile
    
    
    one
    /tmp
    
    
    Home.html
    
    
    Please Help me..

  2. #2
    phoenix is online now Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,579
    Rep Power
    57

    Default

    Where in Zimbra are you trying to do this, in a zimlet?
    Regards


    Bill


    Acompli: A new adventure for Co-Founder KevinH.

  3. #3
    vijaykumardahiya is offline New Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    6

    Default Please let me

    Quote Originally Posted by phoenix View Post
    Where in Zimbra are you trying to do this, in a zimlet?
    what mean Sir,
    Please simplyfy.
    Have I post my question in wrong place..??

  4. #4
    dijichi2 is offline OpenSource Builder & Moderator
    Join Date
    Oct 2005
    Posts
    1,176
    Rep Power
    11

    Default

    yes, this is a forum for a product called Zimbra. you are in the wrong place.

  5. #5
    vijaykumardahiya is offline New Member
    Join Date
    Nov 2008
    Posts
    3
    Rep Power
    6

    Default Please let me know

    Quote Originally Posted by dijichi2 View Post
    yes, this is a forum for a product called Zimbra. you are in the wrong place.
    Dear Sir,
    Can you write me please where I put java related query on this site.
    please let me know.

  6. #6
    dijichi2 is offline OpenSource Builder & Moderator
    Join Date
    Oct 2005
    Posts
    1,176
    Rep Power
    11

    Default

    This forum has nothing to do with Java development. Try google.com

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. bayes db..
    By osiris in forum Administrators
    Replies: 9
    Last Post: 06-15-2011, 11:14 AM
  2. speed up the net
    By mcesari in forum Administrators
    Replies: 10
    Last Post: 04-25-2008, 11:24 AM
  3. centos 5 zimbra 4.5.6 no statistics
    By rutman286 in forum Installation
    Replies: 9
    Last Post: 08-14-2007, 09:30 AM
  4. Traslation SVN tree status
    By meikka in forum I18N/L10N - Translations
    Replies: 7
    Last Post: 02-13-2007, 11:13 AM
  5. M3 problem with shares
    By titangears in forum Users
    Replies: 4
    Last Post: 01-12-2006, 01:01 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
  •