簡體   English   中英

使用jsp和servlet從本地驅動器獲取文件路徑

[英]get file path from local drive with jsp and servlet

我現在想獲取文件路徑時遇到問題。 這是我的代碼:

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>

我只需要完整的文件路徑,請提出任何建議?

您可以在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);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM