我想要获取文件路径时遇到问题。这是我的代码:
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>
我只需要完整的文件路径,请提出建议吗?
答案 0 :(得分:0)
您可以在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);
}