java 获取 <input type="file" 的路径 如何下servlet中获取<input type="file" 参照所得的文件路径 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 filePath = request.getRealPath("/");//取得你当前运行文件在服务器上的绝对路径. 当前站点的根目录 可以用SmartUpload上传组件 System.out.println(su.getFiles().getFile(0).getFieldName());//获取下载的文件夹名 System.out.println(su.getFiles().getFile(0).getFileName());//获取上传的文件全称 System.out.println(su.getFiles().getFile(0).getFilePathName());//获取上传的文件路径及全名 <form action="TestFile"> <table> <tr> <td> <input type="file" id="file1" name="file1"/> </td> <td> <input type="submit" value="提交"/> </td> </tr> </table> </form> public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String str=request.getParameter("file1"); System.out.println(str); }str就是file中的值,再用subString应该可以,不过好像没什么意义 直接用 rerequest.getParameter("file");就可以获得到文件的绝对路径,但如果路径中有中文字符,就要做相应的中文处理了。。 可以用SmartUpload上传组件 System.out.println(su.getFiles().getFile(0).getFieldName());//获取下载的文件夹名 System.out.println(su.getFiles().getFile(0).getFileName());//获取上传的文件全称 System.out.println(su.getFiles().getFile(0).getFilePathName());//获取上传的文件路径及全名 请请各位的回答.我用String pathwrongEncoding=request.getParameter("load"); String readpath=new String(pathwrongEncoding.getBytes(),"GB2312"); out.println(readpath); 怎么找印出来还是不好用呢? request.getInputStream();然后解析这个流,这个流包含了表单所有信息,包括文件以及其他表单项 <input type="file" name="load" id="load" >load 是一个文件上传控件的名字,我想用request.getParameter("load")取路径,能取出来因为我用的是日文系统,所以不支持中文,我用"String readpath=new String(pathwrongEncoding.getBytes(),"GB2312"); "不好用呀,带有中文的部分还是乱码. 直接用request.getParameter("file");就可以获得到文件的绝对路径,但如果路径中有中文字符,就要做相应的中文处理想要中文的就在前面加上request.setCharacterEncoding("UTF-8"); file.getFilePathName();取得上传文件的全名(包括路径) 我用"String readpath=new String(pathwrongEncoding.getBytes(),"GB2312"); "不好用呀,带有中文的部分还是乱码.这样处理中文:String path = request.getParameter("load");path = new String(path.getBytes("ISO8859-1")); web项目运行一段时间后就白屏 如何将表单提交的信息加入数据库中? 求一个实名认证的程序 struts easy question 关于htmi:link链接的问题 求高手解决 javabean的问题,请指点 求救!!! 做了个tomcat的网站,在网站上放了.exe文件,却无法下载,各位走过路过的帮一把吧!!! 请问我在何处可以找到smartUpload组件呢? 请问在JSP中怎样把IP地址转换为整型 如何避免同一个action的重复执行?(详见内) 一个页面要显示多个模型(vo)的数据,action怎么设计?
System.out.println(su.getFiles().getFile(0).getFieldName());//获取下载的文件夹名
System.out.println(su.getFiles().getFile(0).getFileName());//获取上传的文件全称
System.out.println(su.getFiles().getFile(0).getFilePathName());//获取上传的文件路径及全名
<table>
<tr>
<td>
<input type="file" id="file1" name="file1"/>
</td>
<td>
<input type="submit" value="提交"/>
</td>
</tr>
</table>
</form> public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String str=request.getParameter("file1");
System.out.println(str);
}str就是file中的值,再用subString应该可以,不过好像没什么意义
System.out.println(su.getFiles().getFile(0).getFieldName());//获取下载的文件夹名
System.out.println(su.getFiles().getFile(0).getFileName());//获取上传的文件全称
System.out.println(su.getFiles().getFile(0).getFilePathName());//获取上传的文件路径及全名
我用String pathwrongEncoding=request.getParameter("load");
String readpath=new String(pathwrongEncoding.getBytes(),"GB2312");
out.println(readpath);
怎么找印出来还是不好用呢?
然后解析这个流,这个流包含了表单所有信息,包括文件以及其他表单项
load 是一个文件上传控件的名字,我想用request.getParameter("load")取路径,能取出来
因为我用的是日文系统,所以不支持中文,我用"String readpath=new String(pathwrongEncoding.getBytes(),"GB2312"); "不好用呀,带有中文的部分还是乱码.
想要中文的就在前面加上request.setCharacterEncoding("UTF-8");
String path = request.getParameter("load");
path = new String(path.getBytes("ISO8859-1"));