Using <input type=file /> with J2EE/MySQL Backend
I'm wondering how I can hook up an input type=file to send a picture back to a backend servlet that will eventually be stored in a MySQL database as a BLOB? In other words, how can I upload a picture using the input and send that back to the servlet to insert into the database as a BLOB type?
Thanks开发者_运维问答
To browse a file for upload, use HTML <input type="file">
. To be able to send the selected file in request body, use <form method="post" enctype="multipart/form-data">
. To be able to parse the multipart/form-data request, use Apache Commons FileUpload. To get an InputStream
of the uploaded file, use FileItem#getInputStream()
. To let Java interact with a database, use JDBC API. To store an InputStream
in a database, use PreparedStatement#setBinaryStream()
.
精彩评论