snLibrary - FileUploader
(v14.0 dtd. 22-Feb-2012)
When we create forms where we need to upload files to the server from the client side, the following input tag is used.
<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="myfileforUpload" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
In the servlet / jsp code, the following can be used.File:- UploadServlet.java
import servlets.uploader.snUploader;
snUploader snUpld = new snUploader();
DataInputStream dataStream = new DataInputStream(snUpld.snGetUploadedFileItem(request,
"myfileforUpload").getInputStream());
// - or simply -
DataInputStream dataStream = snUpld.snGetUploadedFileDataStream(request,
"myfileforUpload");
BufferedReader buffReader = new BufferedReader(new InputStreamReader(dataStream,
"UTF-8"));
for (String line; (line = buffReader.readLine()) != null;) {
out.println(line + "<br/>\n");
/// Some processing of the input file
}
No comments:
Post a Comment