This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file upload from servlet

 
saheli sen gupta
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you help me with some information regarding , how do i upload a file from servlet
------------------
 
lokesh reddy
Ranch Hand
Posts: 66
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic