如何下servlet中获取<input type="file" 参照所得的文件路径

解决方案 »

  1.   

    filePath = request.getRealPath("/");//取得你当前运行文件在服务器上的绝对路径. 当前站点的根目录 
      

  2.   

    可以用SmartUpload上传组件
    System.out.println(su.getFiles().getFile(0).getFieldName());//获取下载的文件夹名
    System.out.println(su.getFiles().getFile(0).getFileName());//获取上传的文件全称
    System.out.println(su.getFiles().getFile(0).getFilePathName());//获取上传的文件路径及全名
      

  3.   

       <form action="TestFile">
       <table>
        <tr>
        <td>
        <input type="file" id="file1" name="file1"/>
        </td>
        <td>
        <input type="submit" value="提交"/>
        </td>
        </tr>
       </table>
       </form> public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    String str=request.getParameter("file1");
    System.out.println(str);
    }str就是file中的值,再用subString应该可以,不过好像没什么意义
      

  4.   

    直接用 rerequest.getParameter("file");就可以获得到文件的绝对路径,但如果路径中有中文字符,就要做相应的中文处理了。。
      

  5.   

    可以用SmartUpload上传组件 
    System.out.println(su.getFiles().getFile(0).getFieldName());//获取下载的文件夹名 
    System.out.println(su.getFiles().getFile(0).getFileName());//获取上传的文件全称 
    System.out.println(su.getFiles().getFile(0).getFilePathName());//获取上传的文件路径及全名
      

  6.   

    请请各位的回答.
    我用String pathwrongEncoding=request.getParameter("load");
      String readpath=new String(pathwrongEncoding.getBytes(),"GB2312");
      out.println(readpath);
      怎么找印出来还是不好用呢?
      

  7.   

    request.getInputStream();
    然后解析这个流,这个流包含了表单所有信息,包括文件以及其他表单项
      

  8.   

    <input type="file" name="load" id="load" >
    load 是一个文件上传控件的名字,我想用request.getParameter("load")取路径,能取出来
    因为我用的是日文系统,所以不支持中文,我用"String   readpath=new   String(pathwrongEncoding.getBytes(),"GB2312"); "不好用呀,带有中文的部分还是乱码.
      

  9.   

    直接用request.getParameter("file");就可以获得到文件的绝对路径,但如果路径中有中文字符,就要做相应的中文处理
    想要中文的就在前面加上request.setCharacterEncoding("UTF-8");
      

  10.   

    file.getFilePathName();取得上传文件的全名(包括路径)
      

  11.   

      我用"String       readpath=new       String(pathwrongEncoding.getBytes(),"GB2312");   "不好用呀,带有中文的部分还是乱码.这样处理中文:
    String path = request.getParameter("load");
    path = new String(path.getBytes("ISO8859-1"));