<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.multipart.saveDir" value="/chengke"></constant>
<constant name="struts.custom.i18n.resources" value="globalMessages"></constant>
<constant name="struts.devMode" value="true"></constant>
<package name="fileupload" extends="struts-default" namespace="/">
<action name="upload" class="com.chk.action.UploadAction">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/png,image/gif,image/jpeg,image/bmp,image/jpg</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<param name="savePath">/upload</param>
<result>/ok.jsp</result>
<result name="input">/upload.jsp</result>
</action>
</package>
</struts>
文件可以上传了,也可以进行过滤了,但是jpg这个格式的图片无法上传,提示类型不对!其他类型的图片都可以
我就纳闷了,这TMD到底是怎么了,
我的系统是Windows server 2008
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.multipart.saveDir" value="/chengke"></constant>
<constant name="struts.custom.i18n.resources" value="globalMessages"></constant>
<constant name="struts.devMode" value="true"></constant>
<package name="fileupload" extends="struts-default" namespace="/">
<action name="upload" class="com.chk.action.UploadAction">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">image/png,image/gif,image/jpeg,image/bmp,image/jpg</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
<param name="savePath">/upload</param>
<result>/ok.jsp</result>
<result name="input">/upload.jsp</result>
</action>
</package>
</struts>
文件可以上传了,也可以进行过滤了,但是jpg这个格式的图片无法上传,提示类型不对!其他类型的图片都可以
我就纳闷了,这TMD到底是怎么了,
我的系统是Windows server 2008
解决方案 »
- java中纠结的问题
- ExtJs解析数据
- 大虾!spring 定时任务执行方法过程中,有没有可能获取到前台数数据,或者一个js接口的数据
- Java菜鸟求救一个小程序的注释
- !!!!!!!!!JDBC2.0的问题,急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 新手求助struts初级问题 jb2005+struts1.2.4
- 使用JasperReport时出错,java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
- STRUTS中怎样显示resultset的内容?
- 怪事,劳烦各位朋友进来看看~
- 求一个算法
- java socket 疑问
- struts2文件下载出现异常,高手请进
import java.io.FileInputStream;
import java.io.FileOutputStream;import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class UploadAction extends ActionSupport {
private String title;
private File upload;
private String uploadContentType;
private String uploadFileName;
private String savePath; public String getTitle() {
return title;
} public void setTitle(String title) {
this.title = title;
} public File getUpload() {
return upload;
} public void setUpload(File upload) {
this.upload = upload;
} public String getUploadContentType() {
return uploadContentType;
} public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
} public String getUploadFileName() {
return uploadFileName;
} public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
} public String getSavePath() throws Exception{
return ServletActionContext.getServletContext().getRealPath(savePath);
} public void setSavePath(String savePath) {
this.savePath = savePath;
} @Override
public String execute() throws Exception {
System.out.println("开始上传单个文件-----------------------");
System.out.println(getSavePath());
System.out.println("==========" + getUploadFileName());
System.out.println("==========" + getUploadContentType());
System.out.println("==========" + getUpload());
// 以服务器的文件保存地址和原文件名建立上传文件输出流
FileOutputStream fos = new FileOutputStream(getSavePath() + "\\" + getUploadFileName());
// 以上传文件建立一个文件上传流
FileInputStream fis = new FileInputStream(getUpload());
// 将上传文件的内容写入服务器
byte[] buffer = new byte[1024];
int len = 0;
while ((len = fis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
return SUCCESS;
}
}
因为无法上传所以jpg格式的图片无法在后台显示
其他格式的图片可以:
开始上传单个文件-----------------------
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\Struts2_0700_Upload\upload
==========Struts.gif
==========image/gif
==========\chengke\upload_3ab423ce_13541ec41a6__8000_00000007.tmp
firefox浏览器试了一下,发现都可以上传了,但是图片无法展示出来,
这是我上传成功后的显示页面
<body>
上传成功!<br>
文件标题:<s:property value="title"/><br>
文件为:<img alt="" src="upload/"/><s:property value="uploadFileName"/>
在IE中如果没有过滤
上传成功的话是可以显示所上传的图片的但是在firefox浏览器中每种格式的图片都无法显示
红色部分删了试试。
image/jpeg不能删image/jpg可以删IE中还是JPG格式的不行
在firefox和谷歌浏览器中都可以
看来是IE中的某些设置不行,我用的是Windows server 2008,不知道是不是跟系统有关
这个东西代码贴出来