【问题标题】:get file path from local drive with jsp and servlet使用 jsp 和 servlet 从本地驱动器获取文件路径
【发布时间】:2015-08-04 21:13:57
【问题描述】:

我现在想获取文件路径时遇到问题。这是我的代码:

public void service(HttpServletRequest request, HttpServletResponse res)
        throws ServletException, IOException {
    String cabArch = req.getParameter("fRutaArch");
    String rutaArch = getFileName(filePart);
}

在jsp中我有这个:

<td align="left" class="e2">
  <input type="file" name="fRutaArch" id="fRutaArch" title="Seleccionar archivo">                       
</td>
<td>
  <button type="submit" name="bCargar" id="bCargar">Cargar</button>
</td>

我只需要完整的文件路径,请指教?

【问题讨论】:

  • 我认为您实际上不希望客户端上的文件路径(通常这是不可能的),而是将文件上传到 servlet。因此,您可能会发现 this post 很有趣
  • 实际上,我一直在寻找一个不可能的解决方案 xD 无论如何谢谢,我会尝试用另一种方式来处理我的 porpuse

标签: java jsp servlets


【解决方案1】:

可以在html代码中添加a hidden field,修改service函数

代码如下

<td align="left" class="e2">
<input type="file" name="fRutaArch" id="fRutaArch" title="Seleccionar   archivo" onchange="document.getElementById('filepath').value=this.value" >                       
</td>
<td>
<button type="submit" name="bCargar" id="bCargar">Cargar</button>
</td>
<input type='hidden' name='filepath' id='filepath'/>

然后是函数service

public void service(HttpServletRequest request, HttpServletResponse res)
    throws ServletException, IOException {
String cabArch = req.getParameter("filepath");
String rutaArch = getFileName(cabArch);

}

【讨论】:

    猜你喜欢
    • 2017-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 2017-09-23
    • 1970-01-01
    相关资源
    最近更新 更多