request请求获取相对路径和绝对路径

在Action中获取路径

HttpServletRequest request= ServletActionContext.getRequest();

1.request.getSession().getServletContext().getRealPath("")

    打印:D:dsworkspace.metadata.pluginsorg.eclipse.wst.server.core	mp1wtpwebappsecp

2.request.getSession().getServletContext().getRealPath("/")

    打印:D:dsworkspace.metadata.pluginsorg.eclipse.wst.server.core	mp1wtpwebappsecp

3.request.getRequestURI()

    打印:/ecp/bs-ui/ecp/marketingManage.GalleryAction!retrieve.bs

4.request.getContextPath()

   打印:/ecp

5.request.getServletPath()

   打印:/bs-ui/ecp/marketingManage.GalleryAction!retrieve.bs

 
原文地址:https://www.cnblogs.com/zt528/p/4468703.html