WebWork文件上传配置1:导入包
commons-fileupload.jar commons-io-1x.jar
WebWork文件上传配置2:配置webwork.properties文件
- webwork.multipart.parser=jakarta
WebWork文件上传配置3:配置xwork.xml文件
- <!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN"
- "http://www.opensymphony.com/xwork/xwork-1.0.dtd">
- <xwork>
- <include file="webwork-default.xml"></include>
- <package name="default" extends="webwork-default">
- <interceptors>
- <interceptor name="upload" class="com.opensymphony.webwork.interceptor.FileUploadInterceptor"></interceptor>
- <interceptor-stack name="uploadStack">
- <interceptor-ref name="upload"></interceptor-ref>
- <interceptor-ref name="defaultStack"></interceptor-ref>
- </interceptor-stack>
- </interceptors>
- <action name="realAddUpload" class="userAction"
- method="realAddUpload">
- <interceptor-ref name="uploadStack"></interceptor-ref>
- <result name="success" type="redirect">getAllUploads.action</result>
- </action>
- </package>
- </xwork>
WebWork文件上传配置4:写页面
- <form action="realAddUpload.action" method="post"
- enctype="multipart/form-data">
标题:
- <input type="text" name="upload.title">
- <br>
文件上传:
- <input type="file" name="files">
- <br>
- <input type="submit" value="增加资源">
- </form>
WebWork文件上传配置5:写action
- public String realAddUpload() throws Exception {
- if (upload != null) {
- if (files != null) {
- upload.setUploadName(filesFileName);
- userService.addUpload(upload, files);
- }
- }
- return SUCCESS;
- }
【编辑推荐】