我想開發從服務器上傳和下載文件。JSP上傳文件Java.lang.NullPointer
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();
}
}
當我提交的文件我得到空指針錯誤信息。我不是很熟悉jsp有人能幫我嗎?我想將文件存儲到服務器目錄。
我在你之前的問題中已經回答了這個問題,那是不是不夠? http://stackoverflow.com/questions/2930240/jsp-uploading-and-downloading-video – BalusC 2010-05-29 13:32:15
雅對不起,我不明白你的代碼。 – user236501 2010-05-30 04:01:21