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

曾鹏 发布于 2014/06/03 13:23
阅读 44K+
收藏 1

启动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";

}


}

通过访问http://localhost:8080/v20/activity/test/,报如上错误,请各位帮忙看看到底是哪儿配错了?


加载中
1
曾鹏
谢谢各位帮忙解答,现在问题已经解决,是因为自定义的过滤器有点问题,所以出现如上错误。
0
曾鹏
请各位帮帮看看,到底是哪儿配置错误呢?第一次遇到这种问题,请各位帮忙指点!谢谢
0
CCNU
CCNU
@RequestMapping(value = "/test", method = RequestMethod.POST),你这规定是post访问,地址栏直接访问是get方法啊
0
曾鹏
去掉 method = RequestMethod.POST,报同样的错误,主要的配置我都贴出来了,不知道是哪儿配置错误了,现在请求不到controller。从来没有遇到这样的问题,也不知道是不是跟这个工程环境有关,以前使用springmvc也基本上是这样配置的,就没有问题,现在头大了,不知道该怎么搞?
0
F_L_F
F_L_F
<servlet-name>appServlet</servlet-name>

<url-pattern>/</url-pattern>

url-pattern属性错误,改成:/*

0
becke
becke
楼上正解
0
曾鹏

引用来自“F_L_F”的评论

<servlet-name>appServlet</servlet-name>

<url-pattern>/</url-pattern>

url-pattern属性错误,改成:/*

还是不行
0
F_L_F
F_L_F

/WEB-INF/jsp/test.jsp有这文件么?

PS:<url-pattern>/</url-pattern>也是对的

0
红白机
红白机

我看配置都没问题啊。

 http://localhost:8080/v20/activity/test/

 http://localhost:8080/v20/activity/test

注意,这两个是不同的URL mapping呢。按你写的RequestMapping应该是/activity/test才对啊。明白?

红白机
红白机
@曾鹏 贴代码加个格式吧,这样看得眼花。
0
小小志
小小志
No mapping found for HTTP request with URI [/v20/activity/test/] in DispatcherServlet with name 'appServlet',意思就是找不到这个地址,把v20去掉试试
返回顶部
顶部