JSP:
<html:file property="path" styleClass="text2" />
action:
BookForm bookForm = (BookForm) form;
bookForm.getPath();
为什么有的时候是绝对路径,有的时候只显示文件名.扩展名呢?我就要绝对路径,有什么好办法吗?

解决方案 »

  1.   

    你ActionForm中的path属性是什么类型的? 这里得用FromFile类型,Struts的。
      

  2.   

    先取得系统的路径,后面拼接上你的bookForm.getPath()得到的值。
    参照:      File imageFile = new File(ServletActionContext.getServletContext().getRealPath( " /UploadImages " ) + " / " + imageFileName);
    " /UploadImages "是你要把文件上传到你服务器的哪个文件夹下(根目录)
    imageFileName是你的bookForm.getPath()得到的值。
      

  3.   

    request.getRealPath("");
    就可以获取绝对路径了。。