springmvc默认首页问题

Springmvc 默认首页的问题


1. index页面跳转

web.xml 中定义的默认首页:

    <welcome-file-list>  
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

然后在index.html中跳转到springmvc的动态链接
这样地址上就有 http://www.xxx.com/index/servletName

2. 配置默认servlet

web.xml 中如下改动:

<welcome-file-list>
    <welcome-file>index</welcome-file>  <!-- 这里是index   没有后缀名-->
</welcome-file-list> 
<servlet-mapping>
<!-- 这个Servlet的名字是myproject-dispatcher,可以有多个DispatcherServlet,是通过名字来区分的。 每一个DispatcherServlet有自己的WebApplicationContext上下文对象。同时保存到ServletContext中和Request对象中 -->
<servlet-name>myproject-dispatcher</servlet-name>
<!-- 拦截*.do结尾的请求。 -->
  <url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>  
  <servlet-name>myproject-dispatcher</servlet-name>  
  <url-pattern>/index</url-pattern>  
</servlet-mapping>

猜你喜欢

转载自blog.csdn.net/qq250782929/article/details/51538698
今日推荐