No mapping found for HTTP request with URI [/spring/WEB-INF/page/index.jsp] in DispatcherServlet with name 'spring'
2014-02-16 16:24
1406 查看
今天试了下spring mvc遇到个很奇怪的事情,按照书上配置访问时总是出现如下警告:
org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/myspring/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'spring'
web.xml
Xml代码
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springContext.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springContext.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
springContext.xml
Xml代码
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="/hc" class="com.hj.controllers.HelloController"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean name="/hc" class="com.hj.controllers.HelloController"/>
HelloController.java
Java代码
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("hello");
}
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("hello"); }
在项目/WEB-INF/jsp目录下防止hello.jsp文件。按照上述配置访问http://localhost:8081/myspring /hc,应该是出现hello.jsp内容才对,但是却出现了一开始提到的警告。我搜索了许多地方,结果在一老外的提供中找到了同样的问题(http: //forum.springsource.org/archive/index.php/t-71263.html),解决方法老外也说明了,只是不知 道为什么。
就是将web.xml中
Xml代码
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
改成
Java代码
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
spring MVC的困惑--url-pattern的/和/*有区别
Spring MVC 遇到的一点点问题
org.springframework.web.servlet.DispatcherServlet noHandlerFound
警告: No mapping found for HTTP request with URI [/myspring/WEB-INF/jsp/hello.jsp] in DispatcherServlet with name 'spring'
web.xml
Xml代码
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springContext.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet> <servlet-name>spring</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/springContext.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
springContext.xml
Xml代码
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
<bean name="/hc" class="com.hj.controllers.HelloController"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /> <property name="suffix" value=".jsp" /> </bean> <bean name="/hc" class="com.hj.controllers.HelloController"/>
HelloController.java
Java代码
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
return new ModelAndView("hello");
}
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { return new ModelAndView("hello"); }
在项目/WEB-INF/jsp目录下防止hello.jsp文件。按照上述配置访问http://localhost:8081/myspring /hc,应该是出现hello.jsp内容才对,但是却出现了一开始提到的警告。我搜索了许多地方,结果在一老外的提供中找到了同样的问题(http: //forum.springsource.org/archive/index.php/t-71263.html),解决方法老外也说明了,只是不知 道为什么。
就是将web.xml中
Xml代码
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
改成
Java代码
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping> <servlet-name>spring</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
spring MVC的困惑--url-pattern的/和/*有区别
Spring MVC 遇到的一点点问题
相关文章推荐
- No mapping found for HTTP request with URI [/Demo/WEB-INF/page/login.jsp] in DispatcherServlet with
- No mapping found for HTTP request with URI [/spring/WEB-INF/page/index.jsp] in DispatcherServlet with name 'spring'
- 警告: No mapping found for HTTP request with URI [/bks_xk/WEB-INF/jsps/first.jsp] in DispatcherServlet
- No mapping found for HTTP request with URI [/login.do] in DispatcherServlet with name 'spring'
- No mapping found for HTTP request with URI [/index.do] in DispatcherServlet with name 'SpringMVC‘
- Spring : No mapping found for HTTP request with URI in DispatcherServlet with name "..."
- No mapping found for HTTP request with URI [/SpringMVC/hello] in DispatcherServlet with name 'chapte
- No mapping found for HTTP request with URI [/prjName/contro] in DispatcherServlet with name 'spring'
- No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'springmvc'
- No mapping found for HTTP request with URI [/cwgl/department/index] in DispatcherServlet with name
- spring框架的项目报错:No mapping found for HTTP request with URI [ ] in DispatcherServlet with name 'spring'
- 警告: No mapping found for HTTP request with URI [/springmv/iew] in DispatcherServlet with name 'sprin
- IDEA启动WEB项目访问Controller一直提示错误:No mapping found for HTTP request with URI [xxxx] in DispatcherServlet
- No mapping found for HTTP request with URI [/SpringMvc2/ItemList] in DispatcherServlet with name 'sp
- [org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI
- 警告: No mapping found for HTTP request with URI [] in DispatcherServlet with name
- No mapping found for HTTP request with URI [/app17a/] in DispatcherServlet with name 'springmvc'解决方法
- 关于No mapping found for HTTP request with URI和in DispatcherServlet with name 'qht_client'
- No mapping found for HTTP request with URI [/] in DispatcherServlet with name 'projectname'
- 关于警告: No mapping found for HTTP request with URI [/spMVC/] in DispatcherServlet with name 'spMVC'的问题