坐功资深者 2013-06-16 12:34 采纳率: 100%
浏览 35328

spring mvc注解不能访问到controller

web.xml配置

<servlet>  
<servlet-name>annomvc</servlet-name>  
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>   
<init-param>    
<param-name>contextConfigLocation</param-name>    
<param-value>/WEB-INF/annomvc-servlet.xml</param-value>   
</init-param>   
<load-on-startup>2</load-on-startup> 
</servlet> 
<servlet-mapping>   
<servlet-name>annomvc</servlet-name>   
<url-pattern>*.do</url-pattern> 
</servlet-mapping>

annomvc-servlet.xml配置

<context:annotation-config />    
    <!-- 把标记了@Controller注解的类转换为bean -->            
    <context:component-scan base-package="com.svs.master.controller" />

   <!-- 启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->    
  <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />     

   <!-- 对模型视图名称的解析,即在模型视图名称添加前后缀 -->     
   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"     
      p:prefix="/csy/page/" p:suffix=".htm" />
   <bean id="multipartResolver"     
      class="org.springframework.web.multipart.commons.CommonsMultipartResolver"     
      p:defaultEncoding="utf-8" />

controller类

    @Controller@RequestMapping(value = "/userlogin.do")
   public class UserLoginController  {    
   @RequestMapping(params="method=login", method = RequestMethod.POST)    
public String userLogin(HttpServletRequest request,   HttpServletResponse response) throws Exception {    //...方法内容    }}

页面请求

<form method="post" action="userlogin.do?method=login" >

后台错误

20:45:52,098 DEBUG DispatcherServlet:693 - DispatcherServlet with name 'annomvc' processing POST request for [/test/csy/page/userlogin.do]
20:45:52,098  WARN PageNotFound:947 - No mapping found for HTTP request with URI [/test/csy/page/userlogin.do] in DispatcherServlet with name 'annomvc'
20:45:52,098 DEBUG DispatcherServlet:674 - Successfully completed request
  • 写回答

22条回答 默认 最新

  • 钟先珄 2014-11-18 01:34
    关注

    把URL 改成classpath:springmvc.xml看看

    评论

报告相同问题?

悬赏问题

  • ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 如何卸载arcgis 10.1 data reviewer for desktop
  • ¥15 共享文件夹会话中为什么会有WORKGROUP
  • ¥15 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
  • ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
  • ¥15 在matlab中Application Compiler后的软件无法打开
  • ¥15 想问一下STM32创建工程模板时遇到得问题
  • ¥15 Fiddler抓包443
  • ¥20 Qt Quick Android 项目报错及显示问题