there are two buttons in my jsp page
1.
<tr>
<td>
Album Name
</td>
<td>
<input type="text" name="Album" placeholder="Album name"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="submit" name="adddir" value="submit">
</td>
</tr>
2. to upload
<tr>
<td>Upload audio: </td>
<td><input type="file" name="dataFile" id="fileChooser"/></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="Upload" name="upload" />
</td>
</tr>
but only one button work at a time
<form action="uploadservlet" method="post" enctype="multipart/form-data">
servlet code to make a directory which works fine if i write it in
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
String newfolder = request.getParameter("Album");
if(request.getParameter("adddir") != null)
{
File dir = new File("C:/Users/Documents/NetBeansProjects/Registrationform/web/nameoffolder/shreya/" + newfolder);
dir.mkdir();
response.sendRedirect("mypage1.jsp");
}
}
and for uploading
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession sess = request.getSession();
String foldername = sess.getAttribute("uname").toString();
webTempPath = "C:\\Users\\Documents\\NetBeansProjects\\Registrationform\\web\\nameoffolder" +"\\"+ foldername;
try {
// if(request.getParameter("upload") != null)
{
MultipartRequest mpr = new MultipartRequest(request, webTempPath, 10 * 1024 * 1024);
response.setContentType("text/html");
out.println("<html>");
out.println("<head>");
out.println("<title>Server upload</title>");
out.println("</head>");
out.println("<body>");
response.sendRedirect("mypage1.jsp");
out.println("</body>");
out.println("</html>");
}
}
catch (Exception e) {
out.println(e);
response.sendRedirect("Error.jsp");
// request.getRequestDispatcher("/Error.jsp").forward(request, response);
e.printStackTrace();
}
here only one button works at a time. if i write make a directory code in httprequest then it works fine. and the other uploading does not work.if i don't write "make a driectory code" then uploading works fine. But i want user to use both the buttons as per their requirement.