1.创建web项目;
2.导入jar包
3.配置web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>jfinal-fileupload</display-name> <filter> <filter-name>jfinal</filter-name> <filter-class>com.jfinal.core.JFinalFilter</filter-class> <init-param> <param-name>configClass</param-name> <param-value>com.jfinal.config.Myconfig</param-value> </init-param> </filter> <filter-mapping> <filter-name>jfinal</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app> |
4.创建包,并编写上传代码
Myconfig类:
package com.jfinal.config; import com.jfinal.controller.FileUploadController; public class Myconfig extends JFinalConfig{ @Override @Override @Override @Override @Override @Override } |
FileUploadController类:
package com.jfinal.controller; import com.jfinal.core.Controller; public class FileUploadController extends Controller { } |
5.配置静态页面:upload.html
<!DOCTYPE html> </form>
|
6.部署项目到Tomcat,请求http://localhost:8080/jfinal-fileupload/upload.html,上传文件。
上传成功后可以到本地Tomcat下的webapps文件夹中上传文件项目下查看上传的文件。