upload image to jsp

I have a JSP on which I have an upload button. I choose an image from the dialog box and then on clicking "Upload" button, I need to upload the image and also to display it on the screen.
[194 byte] By [j2eebeginnera] at [2007-11-26 18:32:03]
# 1

Upload elements are part of a multipart form, and unfortunately the HttpServletRequest cannot handle those. I suggest you use the FileUpload package to handle multipart requests:

http://jakarta.apache.org/commons/fileupload/using.html

When you do decide to use this, be aware of the dependencies needed for FileUpload to work:

http://jakarta.apache.org/commons/fileupload/dependencies.html

(you only need commons-io)

gimbal2a at 2007-7-9 6:06:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
It is struts framework. It has got action classes, forms and jsps. I need to upload just the image and then display it on the screen. Can we use the FileUpload package for the same purpose? Sorry if it is a stupid question but i don't have much idea about j2ee.
j2eebeginnera at 2007-7-9 6:06:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

try this., this will upload image

InputStream ContentFileInput = null;

try {

String ContentFileName = file.getFileName();

ContentFileInput = file.getInputStream();

boolean isMultipart = FileUpload.isMultipartContent(request);

String uploadDir = servlet.getServletContext().getRealPath(

"/resources")

+ "/";

System.out.println(uploadDir);

uploadDir =uploadDir.substring(0,uploadDir.indexOf("resources")-1);

uploadDir = uploadDir +"\\upload\\";

System.out.println(uploadDir);

uploadDir = uploadDir + filePath;

InputStream mouseStream = file.getInputStream();

OutputStream mousebos = new FileOutputStream(uploadDir

+ ContentFileName);

int bytesRead = 0;

byte[] buffer = new byte[8192];

while ((bytesRead = mouseStream.read(buffer, 0, 8192)) != -1) {

mousebos.write(buffer, 0, bytesRead);

}

String mouseLocation = "The file has been written to \""

+ dirPath.getAbsolutePath() + file.getFileName() + "\"";

System.out.println(mouseLocation);

mousebos.close();

} catch (Exception e) {

System.out.println(e);

loguKKa at 2007-7-9 6:06:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> Can we use the FileUpload package for the same purpose? Sorry if it is a stupid question but i don't have much idea about j2ee.

Somewhere in your struts code you handle the request right? So that is where you would use FileUpload in stead of the regular HttpServletRequest object you get.

gimbal2a at 2007-7-9 6:06:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

> It is struts framework. It has got action classes,

> forms and jsps. I need to upload just the image and

> then display it on the screen.

>

> Can we use the FileUpload package for the same

> purpose? Sorry if it is a stupid question but i don't

> have much idea about j2ee.

its_ajita at 2007-7-9 6:06:10 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...