上传文件时提示
08:55:34,968 ERROR [struts2.interceptor.FileUploadInterceptor] Content-Type not allowed: file "111.txt" "upload_382792d6_12ca124d68c__8000_00000004.tmp" text/plain
但是文件却上传成功了,就是说sturts.xml的限制文件类型失败,文件还是上传了.
<!-- fileUpload拦截器 -->
  <interceptor-ref name="fileUpload">
<!-- 允许单个文件的大小 -->
<param name="maximumSize">512000</param> 
<!-- 允许上传的文件类型,可以到%Tomcat_home%/conf下的web.xml文件中找到所有文件类型的类型名     -->
<param name="allowedTypes">image/jpeg,image/gif</param>
  </interceptor-ref>
  <interceptor-ref name="defaultStack"></interceptor-ref>action文件public String admin_wine_add() throws Exception
{
Date date = new Date();     
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
String imagetype=fileFileName.substring(fileFileName.indexOf("."));//后缀名
FileOutputStream fos=new FileOutputStream("c:/upload"+sdf.format(date)+imagetype); 
        FileInputStream fis=new FileInputStream(file); 
        byte[] buffer=new byte[1024]; 
        int len=0; 
        while((len=fis.read(buffer))>0){ 
            fos.write(buffer, 0, len); 
        } 
        return "success"; 
}
还有个小问题:怎么别人的return SUCCESS;可以的
我也这样写不可以的?

解决方案 »

  1.   

    return "success"; 
    是struts2 默认的一个返回操作,你要在xml文件返回中配置的
      

  2.   

    把你的Action继承ActionSupport就解决了
      

  3.   


    这个我知道,我想知道的是别人的
    return SUCCESS;
    怎么不用双引号括起来?是一个String类型的常量吗?
      

  4.   

    是的 不过你要继承BaseAction
      

  5.   

    因为别人继承了 ActionSupport  ,ActionSupport里面默认实现了 SUCCESS