问题之Spring MVC配置后,可以打开jsp页面,但打不开html页面 |
您所在的位置:网站首页 › jsp跳转html页面 › 问题之Spring MVC配置后,可以打开jsp页面,但打不开html页面 |
一、配置Spring MVC
1.导入jar
spring框架:http://repo.spring.io/release/org/springframework/spring/
spring-framework-4.x.x.RELEASE-dist.zip压缩文件 commons-logging:http://commons.apache.org/解压之后将jar放入 注意:框架默认读取 {servlet-name}-servlet.xml 是配置文件,所以我们在web.xml中写了 spring那么我们写的配置文件就是 spring-servlet.xml 4.编写处理请求的处理器controller,并标记为处理器 package com.ttz.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class HelloWorld { @RequestMapping("/helloworld") public String hello() { System.out.println("hello world"); return "success"; } } 5.编写视图(页面) hello.jsp DOCTYPE html> Insert title here helloworldsuccess.jsp DOCTYPE html> Insert title here 成功! 二、问题启动tomcat可以成功打开hello.jsp,点击后跳转到success.jsp。 但是编写index.html,和success.html,均无法打开 三月 24, 2019 10:02:17 下午 org.springframework.web.servlet.PageNotFound noHandlerFound 警告: No mapping found for HTTP request with URI [/Springmvc-01/index.html] in DispatcherServlet with name 'spring' 三、解决 1.原因分析原因参考:https://blog.csdn.net/jdjdndhj/article/details/54907891 spring /从配置上分析,如此配置会把所有的请求都会进行拦截,交给spring去处理。而spring所有请求的URL都是在controller中使用注解@RequestMapping标明,所以这样的情况下访问静态资源是访问不到的。
spring将index.html页面拦截成请求,而在接口层HelloWorld中没有该请求url对应的处理方法。
???不明白为什么jsp可以 2.解决办法 修改web.xml spring /api/*注意:不能写 /api/ ,得写 /api/* 对应修改页面的请求 helloworld 配置会把 /api/* 所有的请求都会进行拦截 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |