日期:2014-05-18  浏览次数:20787 次

如何在servlet中获得JSP页面的表单元素input type="file"的路径内容
比如我选了F:\abc\cd.txt,想获得这个路径内容,
<form   action= "/WebModule1/servlet "   method= "POST ">
<table   align= "center ">
    <tr>
    <td> 文件位置: </td>
    <td> <input   type= "file "   name= "filePath "> </td>
    </tr>
    <tr>
        <td   colspan= "2 "   width= "30 "   align= "center ">
            <input   type= "submit "   value= "确定 ">
            &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            <input   type= "reset "   value= "重置 ">
        </td>
    </tr>
</table>
</form>
servlet中,String   filePath=request.getParameter( "filePath ");
System.out.println(filePath);不行,系统显示是null.
应该怎么做呢?请各位指教~~

------解决方案--------------------
做上传文件吧
<form action= "/WebModule1/servlet " method= "POST " enctype = "multipart/form-data ">