This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP uploader" Watch "JSP uploader" New topic
Author

JSP uploader

avijit majumder
Greenhorn

Joined: Sep 01, 2009
Posts: 15
hi,
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
Marshal

Joined: Jan 10, 2002
Posts: 61450
    
  67

Have you checked the FAQs?


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

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
Greenhorn

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

put this code in your jsp for file uploading

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

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
if(!fileToCreate.exists()){
FileOutputStream fileOutStream = new FileOutputStream(fileToCreate);
fileOutStream.write(myFile.getFileData());
fileOutStream.flush();
fileOutStream.close();
}
 
 
subject: JSP uploader