| Previous | Home | Next |
In Servlet can be used with an HTML form tag and it allows users to upload files to the server.Servlet can be uploaded file could be a text file or image file or any document.
Using the HTML code to create an uploader form. Some important points are as follows:
- The form method attribute should be set to POST method and GET method can not be used.
- The form enctype attribute should be set to multipart/form-data.
- The form action attribute should be set to a servlet file which would handle file uploading at backend server. Following example is using UploadServlet servlet to upload file.
- To upload a single file you should use a single <input .../ >tag with attribute type="file". To allow multiple files uploading, include more than one input tags with different values for the name attribute. The browser associates a Browse button with each of them.
Example
<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="UploadServlet" method="post"
enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
File Upload: Select a file to upload:
| Previous | Home | Next |