Struts2上传图片时报404错误
可能是struts配置文件中定义的拦截器导致的,后缀拦截导致,将该拦截器去掉,在action类里判断后缀
public String upload()throws Exception{
ActionContext ctxActionContext = ActionContext.getContext();
//this.schoolar = this.expertService.findSchoolarByUid(uid) ;
String directory = ServletActionContext.getServletContext()
.getRealPath(savePath);
File file = new File(directory);
String fileTypesString = MessageUtil.get("fileTypes");// 获取属性文件中规定的附件的文件类型
String fileTypes[] = null;
fileTypes = fileTypesString.split(",");// 所有合法的文件类型后缀构成的字符数组
String suffix = null;// 上传的附件的后缀
suffix = this.getUploadFileName().substring(
this.getUploadFileName().lastIndexOf(".") + 1,
this.getUploadFileName().length());
// 循环判断 后缀是否合法
int count = 0;// 计数器
for (int i = 0; i < fileTypes.length; i++) {
if (fileTypes[i].equalsIgnoreCase(suffix)) {
break;
} else {
count++;
}
}
if (count == fileTypes.length) {
ctxActionContext.put("msg", "文件类型不合法,请核对类型!");
return INPUT;
}
//......
}
最新文章
- expert C Programing notes
- php发送get、post请求的6种方法简明总结
- C# List 中 Find 方法
- Bzoj 4403: 序列统计 Lucas定理,组合数学,数论
- Python学习笔记七-错误和异常
- 被FusionCharts V3.4抛弃的东西
- Java流机制学习
- Java基础学习笔记二十一 多线程
- 关于React Native 火热的话题,从入门到原理
- 制作CSS绚烂效果的三种属性
- cocos2d-js 遮挡层(禁止触摸事件传递层)
- 一加3刷不了官方recoery
- HTTPS 指南
- CSS相对定位|绝对定位(五)之z-index篇——张鑫旭
- 机器学习-ID3决策树算法(附matlab/octave代码)
- EM算法的思考
- jsp的session完成登陆功能
- 【vue】vue组件的自定义事件
- DOM节点的三个属性
- mysql 8.0.12 日常出错
热门文章
- Ubuntu安装Flash
- The P4 Language Specification v1.0.2 Parser
- springMVC框架下——通用接口之图片上传接口
- java.util.concurrent.CopyOnWriteArrayList
- fatal error C1854: 无法覆盖在创建对象文件.obj”的预编译头过程中形成的信息
- Groovy 在eclipse中的使用
- 将所有程序设置XML集中到一个单独XML配置文件的方法:使用appSettings元素的configSource元素
- Tinyxml的简单应用
- IIS出现HTTP500.24错误
- Linux centos关机与重启命令详解与实战