jsp无法引入外部.JS或者.CSS文件的有关问题 (转)

<!-- *************JSP代码******************--> 
<%@ page language="java" pageEncoding="GBK" contentType="text/html;charset=gbk" isELIgnored="false"%> 
<% 
String path = request.getContextPath(); 
// 获得项目完全路径(假设你的项目叫MyApp,那么获得到的地址就是 http://localhost:8080/MyApp/): 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; 
%> 
<html> 
<head> 
<!-- base需要放到head中 --> 
<base href=" <%=basePath%>"> 
</head> 
// 这里我们就可以直接使用相对路径(即: 相对于base标签) 
<a href="jsp/login.jsp">Login </a> 
</html> 
<!-- *************************************-->

 

另参考:http://blog.sina.com.cn/s/blog_03c54d100100wo6n.html

posted @ 2013-10-31 16:26  向大师致敬  阅读(2725)  评论(0编辑  收藏  举报