日期:2014-05-18  浏览次数:20761 次

SSH中关于使用<input type="file">上传文件的问题
<!--jsp页面中-->
    <form action="addPhone" method="post" enctype="multipart/form-data">
     <input type="file" name="dressPhone" />
     <input type="submit" value="提交" />
    </form>

//action中
private File dressPhone;
        public File getDressPhone() {
return dressPhone;
}
public void setDressPhone(File dressPhone) {
this.dressPhone = dressPhone;
}
public String execute() throws Exception {
// TODO Auto-generated method stub
System.out.println(dressPhone.getPath());
return super.execute();
}
struts.xml中
<action name="addPhone" class="addphoneSpring">
<result>/index.jsp</result>
</action>

最后打印出来的结果不管我选什么文件总是
C:\Program Files\Apache Software Foundation\Tomcat 6.0\work\Catalina\localhost\Fitting\upload_7ec3353c_145b0437a40__8000_00000000.tmp
求大神知道是我哪里漏写了什么么.? 
------解决方案--------------------
参考下吧。
------解决方案--------------------
struts2的文件上传就是把文件放在一个临时目录~ 你需要指定文件名~ 并且拷贝到你的指定目录才行~
文件名就是File的变量名加FileName,比如就按你的写法你再定义一个这个打印看看:private String dressPhoneFileName;