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

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 用三极管设计—个共射极放大电路
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示