0 Replies - 2518 Views - Last Post: 13 December 2008 - 01:14 PM Rate Topic: -----

#1 vijaykumardahiya  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 30-November 08

How display a Image on Servlet from File Upload

Post icon  Posted 13 December 2008 - 01:14 PM

Dear Sir,
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.
I try to solve that problem from a long time But Issue are not resolved.
Can you help me Please..
Here my files:
<form method="post" action="tmp" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit"/>

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)
FileUpload fup=new FileUpload();
boolean isMultipart = FileUpload.isMultipartContent(req);
// Create a new file upload handler
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("Length is: "+len); 
byte [] dataBytes = new byte[len]; 
int index=in.read(dataBytes, 0, len);
// res.reset();
res.setHeader("Content-Disposition", "attachment; filename=\"image.jpg\"");
System.out.println("One image writting");
System.out.println("Suceesfully send");
catch(Exception e){System.out.println(e);}


Please Help me..

Is This A Good Question/Topic? 0
  • +

Page 1 of 1