struts2 拦截不允许文件类型成功后,跳转到input页面,但,该action所有方法失效.
只有当把tomcat关闭重新启动后,才恢复action的方法.是不是spring单例问题?注:struts版本2.1.18
spring版本2.5.6
spring旧的版本非单例singleTon="false"
spring新的版本非单例是不是scope="prototype"struts.xml
<action name="add_standardFiles" class="standardFilesAction" method="addStandardFiles">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">text/plain,image/jpeg,application/msword</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result name="success" type="redirectAction">standardFiles</result>
<result name="successAndContinueAdd" type="chain">load_add_standardFiles</result>
<result name="fail" >/standardfiles/add_standardfiles.jsp</result>
<result name="input">/error.jsp</result>
</action>上传的jsp <td>文件名称:</td>
<td><input type="file" name="myFile" id="myFile" /></td>相应Action调用方法
public String addStandardFiles(){
try {
if(myFile==null){
return "fail";
}
String sFileCode = DBProcedure.getCreateTableNo(1);
standardFiles.setFileCode(sFileCode);
standardFiles.setFileObject(myFile);//对象获得文件信息
standardFiles.setFileName(myFileFileName);//对象获得文件名称
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
standardFiles.setStatusDate(sdf.format(new Date()));
HttpSession session = ServletActionContext.getRequest().getSession();
standardFiles.setUserCode(session.getAttribute("staffCode").toString());
standardFiles.setUserName(session.getAttribute("username").toString());
standardFiles.setStatus("1");
standardFilesService.addStandardFiles(standardFiles);
//保存成功后,再打开新增页面等待下一次新增
return SUCCESS;
//System.out.println("N...");
//return SUCCESS;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
只有当把tomcat关闭重新启动后,才恢复action的方法.是不是spring单例问题?注:struts版本2.1.18
spring版本2.5.6
spring旧的版本非单例singleTon="false"
spring新的版本非单例是不是scope="prototype"struts.xml
<action name="add_standardFiles" class="standardFilesAction" method="addStandardFiles">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">text/plain,image/jpeg,application/msword</param>
</interceptor-ref>
<interceptor-ref name="defaultStack" />
<result name="success" type="redirectAction">standardFiles</result>
<result name="successAndContinueAdd" type="chain">load_add_standardFiles</result>
<result name="fail" >/standardfiles/add_standardfiles.jsp</result>
<result name="input">/error.jsp</result>
</action>上传的jsp <td>文件名称:</td>
<td><input type="file" name="myFile" id="myFile" /></td>相应Action调用方法
public String addStandardFiles(){
try {
if(myFile==null){
return "fail";
}
String sFileCode = DBProcedure.getCreateTableNo(1);
standardFiles.setFileCode(sFileCode);
standardFiles.setFileObject(myFile);//对象获得文件信息
standardFiles.setFileName(myFileFileName);//对象获得文件名称
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
standardFiles.setStatusDate(sdf.format(new Date()));
HttpSession session = ServletActionContext.getRequest().getSession();
standardFiles.setUserCode(session.getAttribute("staffCode").toString());
standardFiles.setUserName(session.getAttribute("username").toString());
standardFiles.setStatus("1");
standardFilesService.addStandardFiles(standardFiles);
//保存成功后,再打开新增页面等待下一次新增
return SUCCESS;
//System.out.println("N...");
//return SUCCESS;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
2009-11-14 17:58:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger warn
警告: Content-Type not allowed: myFile "物流与商业服务事业部通讯录.xls" "upload__1e8c6b4f_124f220bc7d__8000_00000001.tmp" application/vnd.ms-excel
2009-11-14 17:58:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Removing file myFile \tmp\upload__1e8c6b4f_124f220bc7d__8000_00000001.tmp
2009-11-14 17:58:02 com.opensymphony.xwork2.util.logging.commons.CommonsLogger info
信息: Removing file myFile \tmp\upload__1e8c6b4f_124f220bc7d__8000_00000001.tmp
<interceptor-ref name="defaultStack" />
<s:file name="myFile" label="File" />
<s:submit />
</s:form>这样写看看?
这个不是问题的根本,是别的错误导致的。
我这里也发现过,页面上说找不到Action,其实是上一次操作的异常导致。
<param name="allowedTypes">text/plain,image/jpeg,application/msword</param>
为什么这个里面没有xls文件呢?