项目配掉端口后有些路径访问不了的解决办法
<%
?String path = request.getContextPath();
?String basePath = null;
?if (request.getServerPort() == 80) {
??basePath = request.getScheme() + "://"
????+ request.getServerName() + path + "/";
?} else {
??basePath = request.getScheme() + "://"
????+ request.getServerName() + ":"
????+ request.getServerPort() + path + "/";
?}
%>
上面这种问题,主要出现在开发,测试阶段,如果用ip+端口访问项目,加上apache之后,配掉端口,于是就默认的是80端口,项目有些路径访问不了(有ajax),所以可以采用上面这种方法来试试。
?
由于项目中很多地方都写了,所以都要改,以后记得把这种变量定义在一个公用的jsp页面,其他页面都引入这个页面。这种思想在开发中非常常见。
<%@ include file="/page/common/jsp/commons.jsp"%>
?