wood burning stoves 2.0*
The moose likes Servlets and the fly likes file upload from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "file upload from servlet" Watch "file upload from servlet" New topic
Author

file upload from servlet

saheli sen gupta
Greenhorn

Joined: Nov 03, 2000
Posts: 13
Can you help me with some information regarding , how do i upload a file from servlet
------------------
lokesh reddy
Ranch Hand

Joined: Sep 15, 2000
Posts: 66
Hi,
If u want to upload a file to the webserver using a servlet, follow these steps.
1. Go to www.servlets.com.
2. Download the oreilly servlet package from there.
3. In that package you will get a java file called
MultipartRequest.java
4. Place it in a proper directory such that its scope is
available to CLASSPATH variable.
5. Compile this java file.
6. Prepare a html form like this.
<html>
<head>
<title>File Uplaod</title>
</head>
<body>
<form method=post enctype="multipart/form-data" action="/servlet/Uploader">
<input type=file name="file">
<input type=submit value=submit>
</form>
</body>
</html>
dont forget to add enctype="multipart/form-data" in the html form.
in the Uploader Servlet initialize the multipartrequest object as follows.
MultipartRequest up=new MultipartRequest(req,"./public_html/temp",1024*1024).
The parameters are
1. HttpServletRequest object.
2. The Path where u want to store the file.
3. The maximum size of the file, that can be uploaded.
I hope u find this info useful.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Lokesh,
I have followed your steps to write the code to upload the file. But i dont find the uploader servlet anywhere. Can you please tell me where i can find this. Please treat this as an urgent request.
Thank you
Jayanthi
Originally posted by lokesh reddy:
Hi,
If u want to upload a file to the webserver using a servlet, follow these steps.
1. Go to www.servlets.com.
2. Download the oreilly servlet package from there.
3. In that package you will get a java file called
MultipartRequest.java
4. Place it in a proper directory such that its scope is
available to CLASSPATH variable.
5. Compile this java file.
6. Prepare a html form like this.
<html>
<head>
<title>File Uplaod</title>
</head>
<body>
<form method=post enctype="multipart/form-data" action="/servlet/Uploader">
<input type=file name="file">
<input type=submit value=submit>
</form>
</body>
</html>
dont forget to add enctype="multipart/form-data" in the html form.
in the Uploader Servlet initialize the multipartrequest object as follows.
MultipartRequest up=new MultipartRequest(req,"./public_html/temp",1024*1024).
The parameters are
1. HttpServletRequest object.
2. The Path where u want to store the file.
3. The maximum size of the file, that can be uploaded.
I hope u find this info useful.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file upload from servlet