在Tomcat与Jetty插件中 配置简化根路径名称
在每次对项目进行访问时,我们都需要输入较长的路径名,这不利于提升访问效率,因此,我们可以通过修改简化根路径的方式提升访问效率。
方法一:省略根页面地址
因为每次访问根页面都需要写 index/,为了高效便捷,我们可以通过两种方式来实现
-
Tomcat
Tomcat可以通过web.xml中添加welcome-file-list标签和springmvc.xml添加mvc:view-controller标签来实现
-
Jetty
在Jetty中利用web.xml形式配置省略根页面地址无效,只能使用在springmvc.xml中添加mvc:view-controller标签的方法简化根路径名称
web.xml
<welcome-file-list>
<welcome-file>/WEB-INF/index.jsp</welcome-file>
</welcome-file-list>
springmvc.xml
<mvc:view-controller path="/" view-name="index" />
方法二:省略项目名地址
相比省略默认页面地址,省略项目名可以更充分的简化缩短根路径的长度
- Jetty 1
省略项目名可以通过在pom文件中添加Jetty插件时更改项目访问路径设置成功
<!-- 添加 maven jetty 插件 -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.14.v20181114</version>
<configuration>
<!-- 端口号 -->
<httpConnector>
<port>9090</port>
</httpConnector>
<!-- 项目访问路径 -->
<webApp>
<contextPath>/</contextPath>
</webApp>
<scanIntervalSeconds>10</scanIntervalSeconds>
</configuration>
</plugin>
方法二内容参考文章来源:https://blog.csdn.net/kai161/article/details/50820247 ↩︎