日期:2014-05-17  浏览次数:20718 次

客户端上传服务器文件问题?
客户端上传服务器文件问题?我使用的是post+流的方式实现,没有使用multiple的方式,因为这种方式不能同时提交其他参数,所以只能使用流的方式,当时有个问题;

  就是本地部署本地上传可以,但是其他机器访问本机,上传的时候却不成功,获取时候获取不到上传文件的路径,只有文件名。不知道为什么?

表单
<form action="../InsertProductServlet" name="product" method="post" >

servlet

String filePath = new String((request.getParameter("file1"))
.getBytes("iso8859-1"), "gb2312");
。。。。

FileInputStream fin = new FileInputStream(filePath);//就是说,其他机器上传时候filePath只是文件名。

------解决方案--------------------
Java code

String path=request.getRealPath("/");     
String url=request.getContextPath();
System.out.println("url:"+url);