请问这个问题时因为找不到 Controller?
我把web.xml springmvc.xml controller.java 这些全给贴出来, 希望大家能够帮我看下, 谢谢了.
工程类目结构:
控制台错误图:
web.xml:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> 3 4 <filter> 5 <filter-name>characterEncoding</filter-name> 6 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 7 <init-param> 8 <param-name>encoding</param-name> 9 <param-value>UTF-8</param-value> 10 </init-param> 11 </filter> 12 13 <filter-mapping> 14 <filter-name>characterEncoding</filter-name> 15 <url-pattern>/*</url-pattern> 16 </filter-mapping> 17 18 <listener> 19 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 20 </listener> 21 <context-param> 22 <param-name>contextConfigLocation</param-name> 23 <param-value>classpath:beans.xml</param-value> 24 </context-param> 25 26 <servlet> 27 <servlet-name>springmvc</servlet-name> 28 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 29 <init-param> 30 <param-name>contextConfigLocation</param-name> 31 <param-value>classpath:springmvc.xml</param-value> 32 </init-param> 33 </servlet> 34 35 <servlet-mapping> 36 <servlet-name>springmvc</servlet-name> 37 <url-pattern>*.do</url-pattern> 38 </servlet-mapping> 39 40 <welcome-file-list> 41 <welcome-file>index.html</welcome-file> 42 <welcome-file>index.htm</welcome-file> 43 <welcome-file>index.jsp</welcome-file> 44 <welcome-file>default.html</welcome-file> 45 <welcome-file>default.htm</welcome-file> 46 <welcome-file>default.jsp</welcome-file> 47 </welcome-file-list> 48 </web-app>
springmvc.xml:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 8 http://www.springframework.org/schema/mvc 9 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context-3.2.xsd 12 http://www.springframework.org/schema/aop 13 http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 14 http://www.springframework.org/schema/tx 15 http://www.springframework.org/schema/tx/spring-tx-3.2.xsd"> 16 <context:component-scan base-package="cn.augmentum"/> 17 18 <mvc:annotation-driven /> 19 20 <!-- 视图解析器: 21 功 能:解析出真正的物理视图 22 返回逻辑视图:success 23 视图解析器:前缀+逻辑视图+后缀===物理视图、 24 :/WEB-INF/jsps/success.jsp 25 --> 26 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 27 <property name="prefix" value="/WEB-INF/jsps/"></property> 28 <property name="suffix" value=".jsp"></property> 29 </bean> 30 31 </beans>
ItemsController.java:
1 package cn.augmentum.controller; 2 3 import org.springframework.stereotype.Controller; 4 import org.springframework.ui.Model; 5 import org.springframework.web.bind.annotation.RequestMapping; 6 7 @Controller 8 @RequestMapping("/items") 9 public class ItemsController { 10 11 @RequestMapping(value="/test") 12 public String test(){ 13 System.out.println("aaaaa"); 14 return "success"; 15 } 16 }
路径是不是{root}/items/test 麽有那个.do的后缀
项目里要配置Controller的包,可以试试对不对路.
<context:component-scan base-package="com.lianrong.manager">
<context:include-filter type="regex"
expression="com.lianrong.manager.controller.*"/>
</context:component-scan>