I'm having some trouble getting my image uploaded to my SQL through JDBC. mySQL table is user(email, pass, name, lastname, profilePicture), profilePicture is sat to blob.
When running I get this excpetion:
SEVERE: Servlet.service() for servlet [changeImage] in context with path [/Event] threw exception [org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header is null] with root cause org.apache.tomcat.util.http.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header is null
my form:
<form method="Post" id="changeImage2" enctype="multipart/form-data">
<input type="file" name="photo" />
<input type="button" value="Submit" id="changeImage1">
</form>
my servlet:
@MultipartConfig
public class changeImage extends HttpServlet{
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
Part filePart = req.getPart("photo");
Object email = req.getSession().getAttribute("email");
Object name = req.getSession().getAttribute("name");
try{
Class.forName("com.mysql.jdbc.Driver");
Connection myConn = DriverManager.getConnection("jdbc:mysql://localhost:3306/logindata", "root", "Simple1337_1");
PreparedStatement ps = myConn.prepareStatement("update user set profilePicture=? where email=? and name=?");
ps.setBlob(1, filePart.getInputStream());
ps.setString(2, (String) email);
ps.setString(3, (String) name);
ps.executeUpdate();
out.println(email);
} catch (Exception e){
e.printStackTrace();
}
}
}
Aucun commentaire:
Enregistrer un commentaire