日期:2014-05-16  浏览次数:20299 次

(转)关于用jspSmartUpload控件上传文件并附带参数的吐血体验

用于上传数据的表单:

<form name="form1" method="post" action="servlet/Upfile" enctype="multipart/form-data">
<p>请输入手机号</p>
<p>
?<input type="text" name="phone" value="1234567890"/>
</p>
<p>图片上传(仅现于*.gif和*.jpg文件)</p>
<p>
<input type="file" name="file1"/>
</p>


<p>
<input type="submit" name="submit" value="· 提交 ·"/>
</p>
</form>

提交的后台的servlet

SmartUpload su =new SmartUpload();
?
? su.initialize(this.getServletConfig(), request, response);
?
? String realPath = this.getServletContext().getRealPath("");
? String path=realPath+"/images";
?
??? su.setAllowedFilesList("gif,jpg");
? su.upload();
? int count=su.save(path);
?
? msdnid=su.getRequest().getParameter("phone");//注意这是接收表单传过来的参数
? System.out.println("msdnid="+msdnid);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

特别说明:用于接收表单参数的语句一定要放在su.upload();语句的后面,也就是说要在文件上传后再接收,否则

不管你怎么试接收到的结果总是"null".

这是我在苦苦试了一天在晕到前的2分钟试出来的,真的不容易呀!!!!!

在上述问题得到解决后,当所传的参数为汉字时则接收到的全是乱码,经过反复实验将表单页面的编码格式设成"gb2312"就解决了这个问题.

?

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/thinker28754/archive/2007/05/26/1626844.aspx