当前位置: 代码迷 >> Java Web开发 >> 客户端上传服务器文件有关问题
  详细解决方案

客户端上传服务器文件有关问题

热度:53   发布时间:2016-04-17 10:27:53.0
客户端上传服务器文件问题?
客户端上传服务器文件问题?我使用的是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);
  相关解决方案