`
xingsan_zhang
  • 浏览: 54251 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

SpringMVC项目设置欢迎首页路径

阅读更多

还是前两天写的小程序,使用MVC架构,展示层使用的是SpringMVC框架。

 

以前使用SpringMVC,没有考虑到首页的路径,这次想到了这个问题。

百度一下,找到了我想要的答案,

 

假设我们的项目名称是demo,要映射localhost:8080/demo/user/add请求,在Controller中使用@RequestMapping("/user/add")就可以映射请求,但是,要映射localhost:8080/demo/请求的话,在Controller中使用@RequestMapping("/")是映射不到请求的,而会走web.xml中的配置文件,如果没有web.xml中配置的默认的相应的页面,就会出现404错误,如果有相应页面,就会跳转到相应页面。

 

使用IDE工具开发,web.xml文件中会默认的跳转页面:

<welcome-file-list>
	<welcome-file>index.html</welcome-file>
	<welcome-file>index.htm</welcome-file>
	<welcome-file>index.jsp</welcome-file>
	<welcome-file>default.html</welcome-file>
	<welcome-file>default.htm</welcome-file>
	<welcome-file>default.jsp</welcome-file>
</welcome-file-list>

 

也就是说,一个请求首先会由web服务器来拦截,之后才会交给SpringMVC处理。所以,我们需要对web.xml进行如下配置:

<welcome-file-list>
	<welcome-file></welcome-file>
</welcome-file-list>

 告诉web服务器,不需要它进行路径拦截处理,直接由SpringMVC处理。

 

参考文章:http://iammr.7.blog.163.com/blog/static/49102699201222643458216/

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics