I want to develope upload and download file from server.
Upload.html
<form action="/UploadFile/UploadFile" method="POST"
enctype="multipart/form-data">Select a file: <input
type="submit" name="button" /> <input type="file" name="first"></form>
UploadFile.servlet
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String temp = request.getParameter("first");
System.out.println(temp);
File origFile = new File(temp);
FileOutputStream out = new FileOutputStream(request.getContextPath()
+ "pdtImages/" + "FirstFile");
InputStream ins = new FileInputStream(origFile);
try {
System.out.println(request.getContextPath());
byte[] buf = new byte[1024];
int len;
while ((len = ins.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
When I submitted the file I got null pointer error message. I not very familiar with jsp can anybody help me? I want to store the file to the server directory.