String uri = req.getRequestURI(); //"/miweb/fplan/index.do"
StringBuffer url = req.getRequestURL(); //"http://localhost:8080/miweb/fplan/index.do"
String cPath = req.getContextPath(); //"/miweb"
String servletPath =req.getServletPath(); //"/fplan/index.do"
String realPath1 = req.getRealPath("/"); //得到工程文件的实际物理路径,也就是绝对地址。不过已经不推荐使用
了。"E:/MoneyTrunk/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/miweb/"
String realPath2 = req.getSession().getServletContext().getRealPath("/"); //得到工程文件的实际物理路径,也就是绝对地
址"E:/MoneyTrunk/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/miweb/"
注:miweb 为工程名
转自:http://blog.youkuaiyun.com/yeshanghai_c/article/details/9001476感谢分享!