To deal with enctype="multipart/form-data" we can not use request.getParameter() directly
Now to deal with the problem
Now, for uploading a file to the server, there can be various ways. But, I am going to use MultipartRequest class provided by oreilly. For using this class you must have cos.jar file.
public class UploadServlet extends HttpServlet
{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
MultipartRequest m=new MultipartRequest(request,"d:/new");
out.print("successfully uploaded");
}
}
this will upload your file to d:/new
Now to retrive parameter of multipart request
you have to use FilenameUtils
class and getOriginalFileName()
method of MultipartRequest
class.
String file = FilenameUtils.getName(req.getOriginalFileName("myfile"))+"\\";
String message = req.getParameter("message");