{"id":223404,"date":"2021-08-08T10:20:18","date_gmt":"2021-08-08T02:20:18","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=223404"},"modified":"2021-07-26T10:21:00","modified_gmt":"2021-07-26T02:21:00","slug":"jsp-file-upload","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/jsp-file-upload.html","title":{"rendered":"JSP\u7b14\u8bb0-\u6587\u4ef6\u4e0a\u4f20"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | JSP\uff08\u5168\u79f0JavaServer Pages\uff09\u662f\u7531Sun Microsystems\u516c\u53f8\u4e3b\u5bfc\u521b\u5efa\u7684\u4e00\u79cd\u52a8\u6001\u7f51\u9875\u6280\u672f\u6807\u51c6\u3002JSP\u90e8\u7f72\u4e8e\u7f51\u7edc\u670d\u52a1\u5668\u4e0a\uff0c\u53ef\u4ee5\u54cd\u5e94\u5ba2\u6237\u7aef\u53d1\u9001\u7684\u8bf7\u6c42\uff0c\u5e76\u6839\u636e\u8bf7\u6c42\u5185\u5bb9\u52a8\u6001\u5730\u751f\u6210HTML\u3001XML\u6216\u5176\u4ed6\u683c\u5f0f\u6587\u6863\u7684Web\u7f51\u9875\uff0c\u7136\u540e\u8fd4\u56de\u7ed9\u8bf7\u6c42\u8005\u3002JSP\u6280\u672f\u4ee5Java\u8bed\u8a00\u4f5c\u4e3a\u811a\u672c\u8bed\u8a00\uff0c\u4e3a\u7528\u6237\u7684HTTP\u8bf7\u6c42\u63d0\u4f9b\u670d\u52a1\uff0c\u5e76\u80fd\u4e0e\u670d\u52a1\u5668\u4e0a\u7684\u5176\u5b83Java\u7a0b\u5e8f\u5171\u540c\u5904\u7406\u590d\u6742\u7684\u4e1a\u52a1\u9700\u6c42\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n
\u672c\u7ae0\u8282\u6211\u4eec\u4f7f\u7528 Servlet \u6765\u5904\u7406\u6587\u4ef6\u4e0a\u4f20\uff0c\u4f7f\u7528\u5230\u7684\u6587\u4ef6\u6709\uff1a<\/p>\n 1.upload.jsp : \u6587\u4ef6\u4e0a\u4f20\u8868\u5355\u3002<\/p>\n 2.message.jsp : \u4e0a\u4f20\u6210\u529f\u540e\u8df3\u8f6c\u9875\u9762\u3002<\/p>\n 3.UploadServlet.java : \u4e0a\u4f20\u5904\u7406 Servlet\u3002<\/p>\n 4.\u9700\u8981\u5f15\u5165\u7684 jar \u6587\u4ef6\uff1acommons-fileupload-1.3.2\u3001commons-io-2.5.jar\u3002<\/p>\n \u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\u4e0a\u4f20\u8868\u5355<\/strong><\/div>\n \u4e0b\u9762\u7684 HTML \u4ee3\u7801\u521b\u5efa\u4e86\u4e00\u4e2a\u6587\u4ef6\u4e0a\u4f20\u8868\u5355\u3002\u4ee5\u4e0b\u51e0\u70b9\u9700\u8981\u6ce8\u610f\uff1a<\/p>\n 1.\u8868\u5355 method \u5c5e\u6027\u5e94\u8be5\u8bbe\u7f6e\u4e3a POST \u65b9\u6cd5\uff0c\u4e0d\u80fd\u4f7f\u7528 GET \u65b9\u6cd5\u3002<\/p>\n 2.\u8868\u5355 enctype \u5c5e\u6027\u5e94\u8be5\u8bbe\u7f6e\u4e3a multipart\/form-data.<\/p>\n 3.\u8868\u5355 action \u5c5e\u6027\u5e94\u8be5\u8bbe\u7f6e\u4e3a\u5728\u540e\u7aef\u670d\u52a1\u5668\u4e0a\u5904\u7406\u6587\u4ef6\u4e0a\u4f20\u7684 Servlet \u6587\u4ef6\u3002\u4e0b\u9762\u7684\u5b9e\u4f8b\u4f7f\u7528\u4e86 UploadServlet <\/p>\n 4.Servlet \u6765\u4e0a\u4f20\u6587\u4ef6\u3002 upload.jsp \u6587\u4ef6\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n <%@ page language=\"java\" contentType=\"text\/html; charset=UTF-8\"\r\n pageEncoding=\"UTF-8\"%>\r\n<!DOCTYPE html PUBLIC \"-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN\"\r\n \"http:\/\/www.w3.org\/TR\/html4\/loose.dtd\">\r\n<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text\/html; charset=UTF-8\">\r\n<title>\u6587\u4ef6\u4e0a\u4f20\u5b9e\u4f8b - \u83dc\u9e1f\u6559\u7a0b<\/title>\r\n<\/head>\r\n<body>\r\n<h1>\u6587\u4ef6\u4e0a\u4f20\u5b9e\u4f8b - \u83dc\u9e1f\u6559\u7a0b<\/h1>\r\n<form method=\"post\" action=\"\/TomcatTest\/UploadServlet\" enctype=\"multipart\/form-data\">\r\n \u9009\u62e9\u4e00\u4e2a\u6587\u4ef6:\r\n <input type=\"file\" name=\"uploadFile\" \/>\r\n <br\/><br\/>\r\n <input type=\"submit\" value=\"\u4e0a\u4f20\" \/>\r\n<\/form>\r\n<\/body>\r\n<\/html><\/pre>\n |