有项目需要,是tomcat绑定域名,但是绑定了之后,
jsp页面 ${pageContext.request.contextPath} 获取不到项目名称
采用如下办法解决:
String basePath = request.getScheme() + "://" + request.getServerName(); if (request.getServerPort() != 80) { basePath += ":" + request.getServerPort(); } basePath+=request.getContextPath(); HttpSession session = request.getSession(); session.setAttribute("basePath", basePath);
登陆之后,将basePath放入session中,使用${sessionScope.basePath} 来代替获取路径