I made HTML form and in the form attribute I added enctype="multipart/form-data" and then used inside the form tag. But when i used to call the servlet on submit button then It i not working. I actually want to upload image from user and add it to one of my folder location. index.html
<input type="file" accept="image/png, image/jpeg">
<input type="Submit">
</form>
revceivefile.java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
Part file=request.getPart("file");
String filename=file.getSubmittedFileName();
String path="C:/Users/MUSTAFA/OneDrive/Desktop/dest/"+filename;
System.out.println(path);
FileOutputStream fout=new FileOutputStream(path);
InputStream is=file.getInputStream();
byte[] data=new byte[is.available()];
is.read(data);
fout.write(data);
fout.close();
}