`

被jsp中的路径困扰

阅读更多

最近使用SpringMVC,在前台页面跳转时总是存在路径跳转问题,所以直接写成了:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

页面中写href=<%=basePaht%>;+“to...”;

若js中有路径,则在页面最前面的script中写

var basePath = <%=basePaht%>;

然后在js代码中使用basePath变量。

这样你的网站就可以随便改域名啦!

请指教!

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics