为了账号安全,请及时绑定邮箱和手机立即绑定

java如何获取jsp页面上传的文件路径

java如何获取jsp页面上传的文件路径

一只斗牛犬 2019-04-12 11:06:00
前台jsp:<form action="AA.do?method=yktAdd" method="post" ><input type='text' name='textfield' id='textfield' class='txt' /> <input type='button' class='btn' value='浏览...' /><input type="file" name="excel" class="file" id="fileField" size="28" onchange="document.getElementById('textfield').value=this.value" /><input type="submit" name="submit" class="btn" value="添加" /></form>后台:public ActionForward yktAdd(ActionMapping mapping,ActionForm form, HttpServletRequest request,HttpServletResponse response) throws Exception {String path=request.getParameter("excel");System.out.println(path);return mapping.findForward("yktadd");}程序得到的结果:XXX.xls我想获取的结果是:D:\XXX.xls 这种全路径只需要一个路径就行了,但是查了好多资料,都不成功,求大神解救!!!!!
查看完整描述

5 回答

?
慕的地3093295

TA贡献1条经验 获得超0个赞

获取文件的绝对路径:this.getClass().getClassLoader().getResource("/").getPath();

希望对你有帮助

查看完整回答
反对 回复 2019-08-05
?
沧海一幻觉

TA贡献1824条经验 获得超5个赞

使用FormFile这个类
定义一个FormBean
public class TestForm{
FormFile file;
private void setFile(FormFile file){
this.file = file;

}
public FormFile getFile(){
return file;
}
}
jsp页面
<input type="file" name="file">
ActionBean
方法中这样写
TestForm tForm = (TestForm)form;// 获取表单
FormFile file = bForm.getFile();
file.getFilePath(); // 获取文件路径



查看完整回答
反对 回复 2019-04-13
  • 5 回答
  • 0 关注
  • 4969 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号