• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP uploader

 
avijit majumder
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65216
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked the FAQs?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic