挨踢农民工的自我修养 2018-08-21 04:25 采纳率: 50%
浏览 782
已采纳

spring mvc 访问页面 的一些问题

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静态页面,而直接通过默认的欢迎页面则可以正常访问呢?

  • 写回答

3条回答

  • qq_18559903 2018-08-21 06:33
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记