前台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();
希望对你有帮助

沧海一幻觉
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(); // 获取文件路径
添加回答
举报
0/150
提交
取消