开发者社区> 问答> 正文

急求:spring mvc3.1访问url报错:org.springframework.web.servlet.PageNotFound

启动tomcat,访问web应用报如下错误:

[org.springframework.web.servlet.PageNotFound] - No mapping found for HTTP request with URI [/v20/activity/test/] in DispatcherServlet with name 'appServlet'

springmvc配置如下:

<bean id="handlerAdapter" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" >
<property name="messageConverters">
       <list>
           <bean id="utf8StringHttpMessageConverter" class=" com.app.chang.anlynis.utils.UTF8StringHttpMessageConverter" />
       </list>
   </property>
</bean>
      
<!-- 扫描所有的controller 但是不扫描service-->
<context:component-scan base-package="com.app.chang.anlynis">
 <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" />
 <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>

<mvc:annotation-driven />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/jsp directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>

    
    <!-- 启用基于注解的处理器映射,添加拦截器,类级别的处理器映射 -->
   <mvc:interceptors>  
      <bean class="com.app.chang.anlynis.utils.HandlerInterceptor" />  
    </mvc:interceptors> 
    <!-- 
配置一个基于注解的定制的WebBindingInitializer,解决日期转换问题,方法级别的处理器映射,
有人说该bean要放在context:component-scan前面,要不然不起作用,但我试的放后面也可以啊。
-->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
   <property name="cacheSeconds" value="0" />
   <property name="webBindingInitializer">
       <bean class="com.app.chang.anlynis.utils.MyWebBinding" />
   </property>
</bean>
</beans>

web.xml配置如下:

<display-name>v20</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<!-- The dataBase definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/root-context.xml</param-value>
</context-param>

    
<!-- validate code -->
  
    <!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- 获得线程绑定的request -->
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/servlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

<!-- 著名 Character Encoding filter -->
<filter>
   <filter-name>characterEncodingFilter</filter-name>
   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
   <init-param>
     <param-name>encoding</param-name>
     <param-value>UTF-8</param-value>
   </init-param>
   <init-param>
     <param-name>forceEncoding</param-name>
     <param-value>true</param-value>
   </init-param>
</filter>
<filter-mapping>
   <filter-name>characterEncodingFilter</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping>
    
    <!-- 浏览器不支持put,delete等method,由该filter将?_method=delete转换为标准的http delete方法  --> 
    <filter>  
   <filter-name>HiddenHttpMethodFilter</filter-name>  
   <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>  
</filter>  
 
<filter-mapping>  
   <filter-name>HiddenHttpMethodFilter</filter-name>  
   <servlet-name>appServlet</servlet-name>  
</filter-mapping> 
<!-- 返回码加载  -->
<servlet>  
        <servlet-name>ReturnDecriptionServlet</servlet-name>  
        <servlet-class>com.app.chang.anlynis.controller.system.SystemServlet</servlet-class>  
        <!-- 启动顺序 -->
        <load-on-startup>20</load-on-startup>  
    </servlet> 
</web-app>


controler如下:

@Controller 
@RequestMapping("/activity")
public class ActivityController extends BaseController {

@RequestMapping(value = "/test", method = RequestMethod.POST)
public String test(Model model) throws Exception {

return "test";

展开
收起
a123456678 2016-03-17 15:12:47 6844 0
1 条回答
写回答
取消 提交回答
  • <url-pattern>/</url-pattern>
    
    url-pattern属性错误,改成:/*`
    2019-07-17 19:05:28
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
Web应用系统性能优化 立即下载
高性能Web架构之缓存体系 立即下载
PWA:移动Web的现在与未来 立即下载