亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么點了上傳之后文件夾里面沒有文件???

為什么點了上傳之后文件夾里面沒有文件???

qq_莫非 2017-12-15 13:03:04
upload.jsp: <%@?page?language="java"?contentType="text/html;?charset=utf-8" ????pageEncoding="utf-8"%> <!DOCTYPE?html?PUBLIC?"-//W3C//DTD?HTML?4.01?Transitional//EN"?"http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"> <title>Insert?title?here</title> </head> <body> <form?action="upload2"?method="post"?enctype="multipart/form-data"> 上傳相片:<input?type="file"?name="photo"/><br><br> <input?type="submit"?value="上傳"?name="upload"/> </form> </body> </html> upload2.java: package?picture; import?java.io.IOException; import?javax.servlet.ServletException; import?javax.servlet.annotation.MultipartConfig; import?javax.servlet.annotation.WebServlet; import?javax.servlet.http.HttpServlet; import?javax.servlet.http.HttpServletRequest; import?javax.servlet.http.HttpServletResponse; import?javax.servlet.http.Part; @MultipartConfig(location="E:/COURSE/") @WebServlet("/upload2") public?class?upload2?extends?HttpServlet?{ private?static?final?long?serialVersionUID?=?1L; ??????? ????public?upload2()?{ ????????super(); ????} protected?void?doGet(HttpServletRequest?request,?HttpServletResponse?response)?throws?ServletException,?IOException?{ request.setCharacterEncoding("utf-8"); Part?part=request.getPart("photo"); String?filename=getFilename(part); part.write(filename); } private?String?getFilename(Part?part)?{ String?header=part.getHeader("Content-Disposition"); String?filename=header.substring(header.indexOf("filename=\"")+10,?header.lastIndexOf("\"")); return?filename; } protected?void?doPost(HttpServletRequest?request,?HttpServletResponse?response)?throws?ServletException,?IOException?{ //?TODO?Auto-generated?method?stub doGet(request,?response); } }求指點
查看完整描述

2 回答

?
慕九州4223353

TA貢獻1條經驗 獲得超0個贊

?String?filename=header.substring(header.indexOf("filename=\"")+10,?header.lastIndexOf("\""));

這一行報錯空指針異常,怎么回事


查看完整回答
反對 回復 2018-04-08
  • 2 回答
  • 0 關注
  • 2002 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號