我创建了一个简单的表单,用户可以选择文件并使用按钮上传。我使用过Struts 2.我选择jpg,txt等文件格式上传,然后创建一个tmp文件。 每当我上传文件后,错误都显示在eclipse上 -
Mar 16, 2018 4:52:00 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
INFO: Removing file uploadFile \EmployeeDocuments\upload__5c8c539e_1622e52a40e__8000_00000002.tmp
以下是文件 -
1)jsp文件
<form action="uploadAction" method="POST" class="basic-form" id="UploadEmpDocument" name="UploadEmpDocument" enctype="multipart/form-data">
<div class="title-bar">
<h4>Upload Documents</h4>
</div>
<div class="inner">
<div class="row">
<div class="col-lg-4 col-md-4 col-xs-12 col-sm-12">
<label>Select File:</label>
<input type="file" name="uploadFile" id="fileToUpload">
<button type="button" name="submit" id="submit" class="btn btn-success">Upload</button>
</div>
</div>
</div>
</form>
2)的struts.xml
<!-- File Upload -->
<action name="UploadDocForm">
<interceptor-ref name="authStack"></interceptor-ref> <!-- authStack, defaultStack -->
<result name="error">view/common/error.jsp</result>
<result name="success">view/employees/UploadDocuments.jsp</result>
</action>
<action name="uploadAction" class="com.zCon.controller.FileUploadAction" method="execute">
<interceptor-ref name="fileUpload"> <!-- authStack,fileUpload -->
<param name="maximumSize">2097152</param> <!-- 2GB? -->
<param name="allowedTypes">
image/png, image/gif, image/jpg, image/jpeg, image/pjpeg, image/pdf, text/plain
</param>
</interceptor-ref>
<!-- <interceptor-ref name="defaultStack"></interceptor-ref> -->
<result name="input">view/employees/UploadDocuments.jsp</result> <!-- UserImage.jsp -->
<result name="success">view/employees/success.jsp</result> <!-- view/employees/UploadDocuments.jsp -->
</action>
<!-- File Upload -->
3)的web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="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>Portal</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
<!-- org.apache.struts2.dispatcher.FilterDispatcher -->
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
提前致谢!!
答案 0 :(得分:0)
请使用
enctype="multipart/form-data"
在jsp frorm中
答案 1 :(得分:0)
它是一种方法
如果您致电onsubmit="return uploadAction"
,请使用action="uploadAction"
代替script method
如果是网址使用
使用action="/uploadAction"
。
在action
/
包含uploadAction