首页 > Web开发 > 详细

Struts 的文件上传问题

时间:2014-10-27 22:56:59      阅读:430      评论:0      收藏:0      [点我收藏+]

   String realpath = ServletActionContext.getServletContext().getRealPath("/images");
        //D:\apache-tomcat-6.0.18\webapps\struts2_upload\images
        System.out.println("realpath: "+realpath);
        if (file != null) {
            System.out.println(file.getName()+":csdcscsd");
            System.out.println(fileFileName+":csdcscsd");
            File savefile = new File(new File(realpath), fileFileName);
            if (!savefile.getParentFile().exists())
                savefile.getParentFile().mkdirs();
            FileUtils.copyFile(file, savefile);
            ActionContext.getContext().put("message", "文件上传成功");
        }

 

 


 <package name="user" namespace="/user" extends="struts-default">
  <result-types>
   <result-type name="json" class="org.apache.struts2.json.JSONResult" />
   <result-type name="html" class="com.rrb.chebao.bean.HtmlResult" />
  </result-types>
  <interceptors>
   <interceptor name="json"
    class="org.apache.struts2.json.JSONInterceptor" />
  </interceptors>
  <action name="*" class="com.rrb.chebao.action.UserAction"
   method="{1}">
   <interceptor-ref name="fileUpload">
    <param name="maximumSize">10485760000</param>
    
   </interceptor-ref>
   <interceptor-ref name="defaultStack" />
   <result type="html" name="html"></result>
   <result type="json" name="json">
    <param name="root">jsonResult</param>
   </result>
  </action>
 </package>

Struts 的文件上传问题

原文:http://www.cnblogs.com/shuixinwen/p/4055337.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!