springMVC RequestMapping请求不到路径
代码展示:
controller层配置:
1
2
3
4
5
6
7
8
9
10
|
@Controller
public class UserController {
private UserService service = new UserServiceImpl();
@RequestMapping (value= "/list" ,method=RequestMethod.GET)
public String list(Model model) throws Exception {
List<User> list = service.getAll();
model.addAttribute( "list" , list);
return "list" ;
}
}
|
web.xml配置:
1
2
3
4
5
6
7
8
9
10
11
12
|
< servlet >
< servlet-name >springmvc</ servlet-name >
< servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class >
< init-param >
< param-name >contextConfigLocation</ param-name >
< param-value >classpath:springmvc.xml</ param-value >
</ init-param >
</ servlet >
< servlet-mapping >
< servlet-name >springmvc</ servlet-name >
< url-pattern >*.action</ url-pattern >
</ servlet-mapping >
|
springmvc.xml的配置:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
< context:component-scan base-package = "cn.jzh" ></ context:component-scan >
< context:annotation-config conversion-service = "dateConverter" ></ context:annotation-config >
<!-- 视图解析 -->
< bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver" >
< property name = "viewClass" value = "org.springframework.web.servlet.view.JstlView" ></ property >
< property name = "prefix" value = "/WEB-INF/view/" ></ property >
< property name = "suffix" value = ".jsp" ></ property >
</ bean >
<!-- 配置转换器 -->
< bean id = "dateConverter" class = "org.springframework.format.support.FormattingConversionServiceFactoryBean" >
< property name = "converters" >
< bean class = "cn.jzh.converter.DateConverter" ></ bean >
</ property >
</ bean >
<!-- 静态放行 -->
< mvc:default-servlet-handler />
|
jsp层,就这一句话:
1
|
<a href= "list.action" rel= "external nofollow" >用户列表</a>
|
发现直接测试接口:项目名+list.action是没用的直接报404的路径找不到
另外,最后跳转的/WEB-INF/view/list.jsp也是存在的
错误所在:
原来是springmvc.xml的配置文件配置错了,注解的映射和驱动错误的使用了context:annotation-config,应该使用的是mvc:annotation-driven
Controller路径的问题RequestMapping(“/...“)导致获取不到页面传递给后台的数据
记录一个error
将RequestMapping路径和一个页面的名称(detail.html)设置成一样的时候,导致根本没有跳转页面!而是直接跳到了传递数据的Controller!
跳转页面的Controller
传递数据的Controller
已解决:
将RequestMapping(“/…“)的路径更改!!!
以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:https://jingzh.blog.csdn.net/article/details/82428140