0

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?

Vogel612
  • 5,620
  • 5
  • 48
  • 73
  • 1
    I think you actually don't want the path of the file on client side (usually that's impossible), but Upload a file to a servlet. As such you may find [this post](https://stackoverflow.com/questions/2422468/) interesting – Vogel612 Aug 04 '15 at 21:16
  • Actually, I was looking for a impossible solution xD anyways thanks I'll try to use another way for my porpuse – Josse Ramírez Aug 04 '15 at 22:04

1 Answers1

0

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

}

Javy
  • 944
  • 5
  • 9