Html Struts2文件上载在生产环境中不起作用,但在本地开发环境中起作用
我正在尝试创建一个具有文件上载功能的网页 FileUpload.jspHtml Struts2文件上载在生产环境中不起作用,但在本地开发环境中起作用,html,tomcat,file-upload,struts2,Html,Tomcat,File Upload,Struts2,我正在尝试创建一个具有文件上载功能的网页 FileUpload.jsp <%@taglib prefix="s" uri="/struts-tags"%> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>file upload Page</title> </head> &
<%@taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>file upload Page</title>
</head>
<body bgColor="lightBlue">
<s:form action="fileUpload" method="post" enctype="multipart/form-data" >
<s:file name="userTmp" label="File" />
<br/>
<s:submit value="uploadFile"/>
</s:form>
</body>
</html>
当我在本地tomcat服务器上运行它时,它工作得很好
但是,当我将其部署到另一个tomcat服务器上时,会出现以下错误:
No result defined for action FileUploadAction and result input
我尝试在FileUploadAction类的execute方法中不做任何事情,只是返回了成功。但它也犯了同样的错误
经过一些代码调试后,我发现这是由于enctype=“multipart/form data”造成的。我用不同的enctype修改了FileUpload.jsp页面,并删除了jsp页面中的
标记,它没有给出任何错误
看起来很奇怪,为什么它在我本地的tomcat服务器上工作,而不是在另一个服务器上工作。
我是否应该更改tomcat服务器中的任何内容以使encype=“multipart/form data”工作…请描述tomcat环境中的差异。例如,版本、默认配置等。我使用的是相同的tomcat版本7.0.32。但是我的是在windows机器上,另一个是linux,它给出了这个错误。我在哪里可以找到默认的configWhy to create
input
result并查看之后会出现什么错误?它只会返回到指定给输入结果类型的页面。但是执行方法甚至没有被调用。将
和
标记放到输入结果页面。还要将日志级别更改为debug,并查看是否有异常。
public class FileUploadAction extends ActionSupport{
private File userTmp;
private String userTmpContentType;
private String userTmpFileName;
Connection conn = null;
public String execute() throws Exception
{
String result = ERROR;
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn= DriverManager.getConnection(".....");
System.out.println("DATABASE CONNECTED");
String sql = "insert into Evidence(Filename, FileType, FileContent,DateSubmitted) values(?, ?, ?, now())";
PreparedStatement pstmt = conn.prepareStatement(sql);
FileInputStream fis = new FileInputStream(userTmp);
pstmt.setString(1, userTmpFileName);
pstmt.setString(2, userTmpContentType);
pstmt.setBinaryStream(3, fis, (int)userTmp.length());
pstmt.executeUpdate();
pstmt.close();
fis.close();
result = SUCCESS;
}
catch (Exception e) {
e.printStackTrace();
}
finally
{
conn.close();
}
return result;
}
public File getUserTmp() {
return userTmp;
}
public void setUserTmp(File userTmp) {
this.userTmp = userTmp;
}
public String getUserTmpContentType() {
return userTmpContentType;
}
public void setUserTmpContentType(String userTmpContentType) {
this.userTmpContentType = userTmpContentType;
}
public String getUserTmpFileName() {
return userTmpFileName;
}
public void setUserTmpFileName(String userTmpFileName) {
this.userTmpFileName = userTmpFileName;
}
}
No result defined for action FileUploadAction and result input