Servlet 3.0 container has standard support for multi-part data. First you must write an HTML page in which the file is entered along with other input parameters.
<form action="uploadservlet" method="post" enctype="multipart/form-data">
<input type="text" name="name" />
<input type="text" name="age" />
<input type="file" name="photo" />
<input type="submit" />
</form>
Now write a UploadServlet that uses the Servlet 3.0 download API. Here is the code that demonstrates the use of the API. A fist that handles multiplayer servlet data must define MultiPartConfig using either of two approaches:
@MultiPartConfig servlet class annotationweb.xml, <multipart-config> <servlet>.
UploadServlet,
@MultipartConfig
public class UploadServlet extends HttpServlet
{
protected void service(HttpServletRequest request,
HttpServletResponse responst) throws ServletException, IOException
{
Collection<Part> parts = request.getParts();
if (parts.size() != 3) {
}
Part filePart = httpServletRequest.getPart("photo");
InputStream imageInputStream = filePart.getInputStream();
filePart.write("somefiepath");
Part namePart = request.getPart("name");
if(namePart.getSize() > 20){
}
InputStream nameInputStream = namePart.getInputStream();
String nameParameter = request.getParameter("name");
Part agePart = request.getPart("age");
int ageParameter = Integer.parseInt(request.getParameter("age"));
}
}
Sevlet 3.0 Container, Apache Commons. Apache Commons:
: