js页面中<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
这个语句是用来拼装当前网页的相对路径的。
request.getSchema()可以返回当前页面使用的协议,就是“http”
request.getServerName()可以返回当前页面所在的服务器的名字,就是“localhost"
request.getServerPort()可以返回当前页面所在的服务器使用的端口,就是8080,
request.getContextPath()可以返回当前页面所在的应用的名字,如名称为“myShopping”。
<base href="...">是用来表明当前页面的相对路径所使用的根路径的。
比如,页面内部有一个连接,完整的路径应该是 http://localhost:8080/myShopping/action/login.do
其中http://server/是服务器的基本路径,myShopping是当前应用程序的名字,那么我的根路径应该是http://localhost:8080/myShopping/。
有<base ... >,路径是可以自动拼装的,不想写全路径的话,只要写 action/login.do就可以,如果没有的话就一定要写全路径,否则服务器会找不到。
posted on 2018-03-09 13:53 mint_sugar 阅读(756) 评论(0) 收藏 举报
浙公网安备 33010602011771号