File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP uploader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP uploader" Watch "JSP uploader" New topic

JSP uploader

avijit majumder

Joined: Sep 01, 2009
Posts: 15
I want to upload a file[ image file or any other file ]
I need the functionality --- user brows a file from client computer
and then press Upload button the backGround jsp/java file upload it to my "tomcat 5.5\webapps\TEST\IMAGES" folder.
any one help me???
write the code.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

Have you checked the FAQs?

[Asking smart questions] [About Bear] [Books by Bear]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

There are libraries that are available to help you, and this information is in the FileUpload section of the FAQ. If you would like more information on what happens under the covers then in many cases the source code is available, or you can solve the problem at hand if that is what you need.
srikanth nallapaneni

Joined: Jun 08, 2009
Posts: 4
This is code works in Struts :

put this code in your jsp for file uploading

<td width="25%">File to be Upload</td>
<td><html:file property="theFile" /></td>

Use this in your Action :
Where uploadForm is an object of form bean with getter and setter methods

FormFile myFile = uploadForm.getTheFile();
String fileName = myFile.getFileName();
System.out.println("File name :"+fileName);

myfile is the uploaded file, Now you got the uploaded file

filepath--- specify the path where new file to be created.

File fileToCreate = new File(filePath, fileName);
//If file does not exists create file
FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
subject: JSP uploader
It's not a secret anymore!