为什么struts2上传得到的都是.tmp的文件 请教各位大虾:为什么struts2上传得到的都是.tmp的文件?望指导,谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 //jsp文件<s:form action="loginInfo_uploadFile" enctype="multipart/form-data"> <table> <tr> <td height="40">文件地址:</td> <td bgcolor="#FFFFFF"><s:file name="upload"/></td> </tr> <tr> <td><s:submit value=" 添加文件 "/></td> </tr> </table> </s:form>//Actionprivate File upload; public void setUpload(File upload) { this.upload = upload; }public String uploadFile(){ String address = System.currentTimeMillis() + upload.getName().substring( upload.getName().lastIndexOf("."));File imageFile = new File(ServletActionContext.getServletContext() .getRealPath("/pic") + "/" + address); copy(upload, imageFile);return SUCCESS; }private static void copy(File src, File dst) { try { InputStream in = null; OutputStream out = null; try { in = new BufferedInputStream(new FileInputStream(src)); out = new BufferedOutputStream(new FileOutputStream(dst)); byte[] buffer = new byte[1024 * 10]; while (in.read(buffer) > 0) { out.write(buffer); } } finally { if (null != in) { in.close(); } if (null != out) { out.close(); } } } catch (Exception e) { e.printStackTrace(); }}// struts.xml<action name="xxx" class="xxxx" method="{1}"> <param name="savePath">/pic</param> <interceptor-ref name ="fileUpload"> <param name="maximumSize">1024000</param> </interceptor-ref> <interceptor-ref name ="defaultStack"/> .....//struts.propertiesstruts.ui.theme=simplestruts.i18n.encoding=utf-8struts.action.extension=htmstruts.multipart.saveDir=d:/tmpstruts.objectFactory = spring .tmp是struts的临时文件,上传完成后即可得到完整的文件估计是上传过程中出现错误啊 <interceptor-ref name ="fileUpload"> <param name="maximumSize">1024000 </param> </interceptor-ref> 或许是因为这个的缘故吧 可能你上传的文件太大了 中途就断了? 猜的 我用的时候没出现过 菜鸟跪求问关于猜拳的java问题 struts2整合struts1添加权限拦截出现的异常 网站首页设置为静态 lniux上怎么挂U盘呀 java编程的朋友进来 用什么方法能够 防止没有注册的用户直接输入网址 登陆只能是注册用户浏览的网页? JMS运行环境问题求助(刚接触不久,见笑) JSP的商品详细信息问题``急的尿裤子了`` logic:iterate 输出时截取字符串 XML问题:不能正确显示,请高手指教! jsp页面中 怎么通过el表达式获得集合中的值的总和 struts2验证用户登录问题
<s:form action="loginInfo_uploadFile" enctype="multipart/form-data">
<table>
<tr>
<td height="40">文件地址:</td>
<td bgcolor="#FFFFFF"><s:file name="upload"/></td>
</tr>
<tr>
<td><s:submit value=" 添加文件 "/></td>
</tr>
</table>
</s:form>//Action
private File upload;
public void setUpload(File upload) {
this.upload = upload;
}
public String uploadFile(){
String address = System.currentTimeMillis()
+ upload.getName().substring(
upload.getName().lastIndexOf("."));
File imageFile = new File(ServletActionContext.getServletContext()
.getRealPath("/pic")
+ "/" + address);
copy(upload, imageFile);
return SUCCESS;
}private static void copy(File src, File dst) {
try {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(src));
out = new BufferedOutputStream(new FileOutputStream(dst));
byte[] buffer = new byte[1024 * 10];
while (in.read(buffer) > 0) {
out.write(buffer);
}
} finally {
if (null != in) {
in.close();
}
if (null != out) {
out.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}// struts.xml
<action name="xxx" class="xxxx" method="{1}">
<param name="savePath">/pic</param>
<interceptor-ref name ="fileUpload">
<param name="maximumSize">1024000</param>
</interceptor-ref>
<interceptor-ref name ="defaultStack"/>
.....
//struts.properties
struts.ui.theme=simple
struts.i18n.encoding=utf-8
struts.action.extension=htm
struts.multipart.saveDir=d:/tmp
struts.objectFactory = spring
估计是上传过程中出现错误啊
<param name="maximumSize">1024000 </param>
</interceptor-ref> 或许是因为这个的缘故吧 可能你上传的文件太大了 中途就断了? 猜的 我用的时候没出现过