I am trying to insert data's and image path into database. But only the image name and path is getting stored in database and remaining column is null can you please help me out
below is my servlet and im new to jsp and servlet
protected void ProcessRequest(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
throws ServletException, IOException {
String Title = request.getParameter("title");
String Keyword = request.getParameter("key");
String Message = request.getParameter("mess");
if(ServletFileUpload.isMultipartContent(request)){
try {
List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request);
for(FileItem item : multiparts){
if(!item.isFormField()){
String name = new File(item.getName()).getName();
item.write( new File(UPLOAD_DIRECTORY + File.separator + name));
String Path = "Upload/" + name;
Connection con = connection.useConnection();
// Statement st = con.createStatement();
// String q = "insert into image_details(Title,Keyword,Description,ImageName,ImagePath) values('" + Title + "','" + Keyword + "','" + Message + "','" + name + "','" + Path + "')";
// System.out.println(q);
// st.executeUpdate(q);
String Query = "insert into image_details(Title,Keyword,Description,ImageName,ImagePath) values (?,?,?,?,?)";
PreparedStatement ps = con.prepareStatement(Query);
ps.setString(1, Title);
ps.setString(2, Keyword);
ps.setString(3, Message);
ps.setString(4, name);
ps.setString(5, Path);
ps.executeUpdate();
System.out.println(ps);
}
}
//File uploaded successfully
//request.setAttribute("message", "File Uploaded Successfully");
} catch (Exception ex) {
request.setAttribute("message", "File Upload Failed due to " + ex);
}
}
// response.sendRedirect("Admin_FileUpload.jsp?msg=1");
request.getRequestDispatcher("/Admin_FileUpload.jsp").forward(request, response);
}
@Override
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
ProcessRequest(request,response);
}
@Override
protected void doPost(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
ProcessRequest(request,response);
}
}
This is my JSP page
<form action="ImageUpload" method="post" enctype="multipart/form-data">
<h3 style="font-family:Raleway,sans-serif;">UPLOAD YOUR CONTENTS AND IMAGES</h3>
<hr/>
<div class="form-group">
<h4 style="font-family:Raleway,sans-serif">Title:</h4>
<input type="text" class="form-control" name="title" placeholder="Enter the Title" required="">
</div>
<div class="form-group">
<h4 style="font-family:Raleway,sans-serif">Keyword:</h4>
<input type="text" class="form-control" required="" placeholder="Enter the Keyword" name="keyword">
</div>
<div class="form-group">
<h4 style="font-family:Raleway,sans-serif">Description:</h4>
<textarea class="form-control" name="mess" required="" rows="5" cols="50"></textarea>
</div>
<div class="form-group">
<h4 style="font-family:Raleway,sans-serif">Image Upload:</h4>
<input type="file" name="Image" style="font-family:Raleway,sans-serif;font-size:17px" class="btn btn-default" required="" >
</div>
<div class="form-group">
<input type="submit" class="btn btn-success" name="Upload" value="Upload" style="width:150px;height:45px">
</div>
</form>