springMVC最简单的demo。webapp/index.html。webapp/WEB-INFO/jsp/index.jsp。两个测试页面。。pom中配置tomcat插件进行启动
控制器
@Controller
public class HelloController {
@RequestMapping("/hello")
public ModelAndView hello(){
ModelAndView mav = new ModelAndView();
mav.addObject("hello", "大家");
mav.setViewName("/WEB-INF/jsp/index.jsp");
return mav;
}
@RequestMapping("/demo")
public String index(){
return "/index.html";
}
}
pom中tomcat的配置
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<port>8080</port>
<path>/test</path>
<uriEncoding>UTF-8</uriEncoding>
<server>tomcat7</server>
</configuration>
</plugin>
jsp
<html>
<head>
<title>环境测试</title>
</head>
<body>
你好,世界!${hello}
</body>
</html>
<mvc:default-servlet-handler /> 默认servlet
不配置默认servlet
,http://localhost:8080/test/hello jsp页面正常访问,显示 ‘ 你好,世界!大家;
http://localhost:8080/test/demo 报404,html页面无法访问。
http://localhost:8080/test/ 报404,html页面无法访问。
配置 默认servlet
,http://localhost:8080/test/hello 报404, jsp页面无法访问;
http://localhost:8080/test/demo 报404,html页面无法访问;
http://localhost:8080/test/ html页面正常访问;
我的问题是,
1,为什么配置 默认servlet 后,jsp页面无法访问了?
2,配置 默认servlet 后, 通过controller无法访问html静态页面,而直接通过默认的欢迎页面则可以正常访问呢?