简体   繁体   中英

get file path from local drive with jsp and servlet

I have a problem at the moment when I want to get the file path. This is my code:

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

And in jsp I have this:

<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>

I just need the full file path, please any advice?

You can add a hidden field in the html code and modify the service function

the code follows below

<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'/>

then the function service

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

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM