- 前言
项目名称为portal,主页面Index.jsp

url访问主页面路径:
http://localhost:8080/portal/index.jsp
期望url
1<!-- 不需要项目名"/portal" --> 2http://localhost:8080/index.jsp
页面中资源文件引用路径
1<head> 2<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 3<title>主页面</title> 4<link rel="stylesheet" type="text/css" href="https://my.oschina.net/portal/css/index.css"> 5<script type="text/javascript" src="https://my.oschina.net/portal/jquery/jquery.min.js"></script> 6<!-- 期望值 --> 7<!-- 8<link rel="stylesheet" type="text/css" href="https://my.oschina.net/css/index.css"> 9<script type="text/javascript" src="https://my.oschina.net/jquery/jquery.min.js"></script> 10--> 11</head>
正常情况下,各种路径中都需要使用项目名"/portal/",如果需要换个项目名或者把其部署到其他项目下,就比较尴尬了。
- 正文
如何忽略掉项目名,即使用期望的路径?
1.tomcat服务器
找到tomcat的server.xml
1 <Context docBase="portal" path="/portal" reloadable="true" 2 source="org.eclipse.jst.j2ee.server:portal"/>
把path值改为"/"
1 <Context docBase="portals" path="/" reloadable="true" 2 source="org.eclipse.jst.j2ee.server:portals"/>
其实,就一个配置项这么简单。
2.其他web服务器
如jetty、weblogic等,待完善。