The form in the HTML is like
...
<form method="post" action="/foobar">
<input type="file" name="attachment" />
<input type="text" name="foo" />
... other input fields
</form>
And the Servlet will be like
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String attachment = request.getParameter("attachement");
String foo = request.getParameter("foo");
// get other parameters from the request
// and get the attachment file
}
And I'm wondering
Is there any ways that do not use 3rd-party libraries to get files from a HttpServletRequest
object?
What request.getParameter("attachement")
returns? Is it the file name or something else?
Would the binary input be stored automatically by a web container in file system or just in memory temporarily?
before anythging your form action should be "POST" and enctype="multipart/form-data".
that said...for you to get the file you must prepare the request yourself.
you should check:
Multipart requests/responses java
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With