我的JSP是在WEB-INF / JSP /,和以下是我的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而我试图访问的映射:
@Controller
@RequestMapping("/product.action")
public class ProductController {
/**
* Show the product selection form
*
* @return
*/
@RequestMapping(method=RequestMethod.GET)
public String get() {
return "products.jsp";
}
}
当试图从以下链接访问该页面:
http://localhost:8080/myapp/product.action
我得到404
在浏览器中,我也得到在控制台以下警告:
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'
我失去了在配置上的东西吗? 请指教,谢谢。
编辑 :我尝试添加视图解析器的bean来的applicationContext没有运气:
<?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>