서버에서 파일 업로드 및 다운로드를 원합니다. 내가 파일을 제출하면하고 Upload.htmlJSP 업로드 파일 Java.lang.NullPointer
<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();
}
}
나는 널 포인터 오류 메시지를 받았습니다. jsp에 익숙하지 않은 사람이 누구든지 나를 도울 수 있습니까? 파일을 서버 디렉토리에 저장하려고합니다.
이전 질문에서 이미 대답했는데, 어떻게 그 정도면 충분하지 않습니까? http://stackoverflow.com/questions/2930240/jsp-uploading-and-downloading-video – BalusC
죄송합니다. 귀하의 코드를 이해할 수 없습니다. – user236501