Step 1: Configure web.xml, add <multipart-config>
<multipart-config>
<max-file-size>1234</max-file-size>
<max-request-size>5678</max-request-size>
</multipart-config>
Step 2: Configure html file
<form name="MyUpload" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file" value="" />
<input type="submit" />
</form>
Step 3: Configure Servlet
InputStream inputStream = request.getPart("file").getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte buffer[] = new byte[12345];
int size = 0;
while ((size = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, size);
}
String MyFile = outputStream.toString();
0 Comment(s)