我在上次的时候如果上传类型和大小没有问题可以上传成功,但是如果上传了一个部分允许的类型或超出大小范围后失败,而且之后再上传正常的文件也上传不了,也不报错,这是为什么呢org.apache.struts2.dispatcher.ActionContextCleanUp这个也设了,加了日志也没有错误,应该不是ACTION里面的代码问题,是不是需要什么配置呢?
解决方案 »
- struts2 jpa(hibernate) spring 启动tomcat报错,急啊
- Dynamin Web Project中如何导入JSTL包
- JDBC错误,望指教啊
- webwork问题!
- hibernate级联更新的问题
- 初次使用java native函数最常见的问题
- 各位大虾,救命啊。。。。。。。、、、、
- 查询数据库(oracle)的日期型字段,用rs.getDate("XXX")得到的值赋给一个java.util.Date型的变量
- 本人刚学java,对j2ee的一些技术有一些困惑
- 参数与返回值不固定的方法如何发布成webservice
- struts2 上传问题
- 请问个有关Spring Security的passwordEncoder用户密码加密问题
请将stacktrace贴出
这是ACTION:
try {
String subfix = this.fileName.substring(this.fileName
.lastIndexOf(".")); if (subfix.equals(".doc") || subfix.equals(".docx")) {
this.savePath = this.savePath + "/" + "doc";
} else if (subfix.equals(".bmp")) {
this.savePath = this.savePath + "/" + "bmp";
} else if (subfix.equals(".jpg") || subfix.equals(".jpeg")) {
this.savePath = this.savePath + "/" + "jpg";
} else if (subfix.equals(".gif")) {
this.savePath = this.savePath + "/" + "gif";
} else if (subfix.equals(".exe")) {
this.savePath = this.savePath + "/" + "exe";
}
desFilename = ServletActionContext.getServletContext().getRealPath(
this.savePath)
+ "/"
+ System.currentTimeMillis()
+ this.saveFilename
+ subfix;
File destFile = new File(desFilename); BufferedInputStream in = new BufferedInputStream(
new FileInputStream(this.uFile), this.UPLOAD_BUFFER_SIZE);
BufferedOutputStream out = new BufferedOutputStream(
new FileOutputStream(destFile), this.UPLOAD_BUFFER_SIZE); byte[] data = new byte[this.UPLOAD_BUFFER_SIZE]; int len; while ((len = in.read(data)) > 0) { out.write(data, 0, len);
}
in.close();
out.close();
desFilename = this.savePath + "/" + System.currentTimeMillis()
+ this.saveFilename + subfix;
desFilename = desFilename.substring(1);
return SUCCESS;
} catch (Exception ex) {
log.error("失败", ex);
return ERROR;
}
struts.xml
<!-- 上传文件 -->
<action name="fupload" class="fileAction" method="uploadFile">
<param name="savePath">/upload</param>
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/bmp,image/jpg,image/pjpeg,image/jpeg,image/gif,application/msword</param>
<param name="maximumSize">10240000</param>
</interceptor-ref>
<!-- 必须加这个拦截器 -->
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success">
/UI/UploadFile/uploadSuccess.jsp
</result>
<result name="input">/UI/EerrorPages/505.jsp</result>
</action>