I'm in the early phases of creating my first blog with Java and, so far, I wrote two different JSPs: - NewArticle.jsp, where I can fill out all data to be displayed in the home page (article, title, data, links and images) - Home.jsp, displaying all information from NewArticle.
I am able to pass all text data from NewArticle to Home but unfortunately I'm unable to pass any image. I read dozens of posts about how this can be done, but I am still totally lost and I really need some help.
This is the upload form from NewArticle.jsp (I removed all input types=text) :
<!DOCTYPE html>
<html lang="en">
<head>
<title>File Upload</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form method="POST" action="upload" enctype="multipart/form-data" >
File:
<input type="file" name="file" id="file" /> <br/>
<input type="submit" value="Upload" name="upload" id="upload" />
</form>
</body>
</html>
This is the code I wrote in my servlet so far:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Part filePart = request.getPart("file");
String fileName = filePart.getSubmittedFileName();
InputStream fileContent = filePart.getInputStream();
Unfortunately I am blocked here, because I don't know how to finalize the code in the servlet.
Any help, please?