启动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/,报如上错误,请各位帮忙看看到底是哪儿配错了?
谢谢各位帮忙解答,现在问题已经解决,是因为自定义的过滤器有点问题,所以出现如上错误。请各位帮帮看看,到底是哪儿配置错误呢?第一次遇到这种问题,请各位帮忙指点!谢谢<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">@RequestMapping(value="/test",method=RequestMethod.POST),你这规定是post访问,地址栏直接访问是get方法啊去掉<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">method=RequestMethod.POST,报同样的错误,主要的配置我都贴出来了,不知道是哪儿配置错误了,现在请求不到controller。从来没有遇到这样的问题,也不知道是不是跟这个工程环境有关,以前使用springmvc也基本上是这样配置的,就没有问题,现在头大了,不知道该怎么搞?<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><servlet-name>appServlet</servlet-name>
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><url-pattern>/</url-pattern>
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">url-pattern属性错误,改成:/
楼上正解<divclass='ref'><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><url-pattern>/</url-pattern>
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">url-pattern属性错误,改成:/
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">/WEB-INF/jsp/<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">test.jsp有这文件么?
<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">PS:<spanstyle="color:#333333;font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;"><url-pattern>/</url-pattern>也是对的
我看配置都没问题啊。
http://localhost:8080/v20/activity/test/
http://localhost:8080/v20/activity/test
注意,这两个是不同的URLmapping呢。按你写的<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">RequestMapping应该是/activity/test才对啊。明白?
<aclass='referer'target='_blank'>@曾鹏贴代码加个格式吧,这样看得眼花。<spanstyle="font-family:微软雅黑,Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">NomappingfoundforHTTPrequestwithURI[/v20/activity/test/]inDispatcherServletwithname'appServlet',意思就是找不到这个地址,把v20去掉试试版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。