Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

file upload from servlet

 
Greenhorn
Posts: 13
  • 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
------------------
 
Ranch Hand
Posts: 66
  • 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.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • 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.


 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic