最近写项目,老是搞不明白这几个到底返回的是啥,特地打印记录一下!!!
//项目名为空
ServletActionContext.getRequest().getRequestURL():http://localhost:9091/startPage/startPageAction!addTbStartPagePO.actionServletActionContext.getRequest().getServletPath():/startPage/startPageAction!addTbStartPagePO.action
ServletActionContext.getRequest().getContextPath():
ServletActionContext.getRequest().getRequestURI():/startPage/startPageAction!addTbStartPagePO.action
//项目名不为空 以/oa为例:
ServletActionContext.getRequest().getRequestURL():http://localhost:9091/oa/startPage/startPageAction!addTbStartPagePO.action
ServletActionContext.getRequest().getServletPath():/startPage/startPageAction!addTbStartPagePO.action
ServletActionContext.getRequest().getContextPath():/oa
ServletActionContext.getRequest().getRequestURI():/oa/startPage/startPageAction!addTbStartPagePO.action
//获取项目地址 返回http://localhost:9091
String requestURL = ServletActionContext.getRequest().getRequestURL().toString();
String serlvetPath = ServletActionContext.getRequest().getServletPath();
String url = requestURL.substring(0,requestURL.indexOf(serlvetPath));