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>