问题描述
我的jsps在WEB-INF/jsp/下,以下是我的web.xml:
my jsps are under WEB-INF/jsp/ , and following is my web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Checkout</display-name>
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>
这是我尝试访问的product.jsp页面的映射:
and here's mapping of page product.jsp which i am trying to access:
@Controller
@RequestMapping("/product.action")
public class ProductController {
/**
* Show the product selection form
*
* @return
*/
@RequestMapping(method=RequestMethod.GET)
public String get() {
return "products.jsp";
}
}
当尝试通过以下链接访问页面时:
when trying to access the page from the following link:
http://localhost:8080/myapp/product.action
我在浏览器中得到404
,并且在控制台中收到以下警告:
i am getting 404
in the browser, and i get the following warning in the console:
Jun 28, 2012 10:55:23 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/myapp/product.action] in DispatcherServlet with name 'myservlet'
我是否在配置中缺少某些内容?请指教,谢谢.
am i missing something in the configuration ?please advise, thanks.
编辑:我尝试将viewResolver bean添加到applicationContext时没有运气:
EDIT: i tried adding the viewResolver bean to applicationContext with no luck:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">
<context:component-scan base-package="com.myapp"/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
推荐答案
问题是未检测到控制器.我将基本软件包从com.myapp
更改为com.myapp.controller
,现在可以正常使用了.
problem was that the controller wasn't detected.i changed the base-package from com.myapp
to com.myapp.controller
, and it works fine now.
这篇关于org.springframework.web.servlet.DispatcherServlet noHandlerFound(未找到映射)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!