我已经按照以下方式配置了使用Spring 3.1.1.RELEASE的 Spring MVC 应用程序
web.xml
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/context/*-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/cgi/*</url-pattern>
</servlet-mapping>
springmvc-servlet.xml
<context:component-scan base-package="com.pokuri.mvc.controllers"/>
用户控制器.java
package com.pokuri.mvc.controllers;
@Controller
@RequestMapping("/user")
public class UserController {
@RequestMapping(method=RequestMethod.GET)
@ResponseBody
public String defaultRequest(){
return "It's a default handler method";
}
}
索引.jsp
<a class="action" href="cgi/user">Default Action</a>
服务器登录初始化springmvc应用程序:
23:53:04,406 INFO [DispatcherServlet] FrameworkServlet 'springmvc': initialization started
23:53:04,468 INFO [XmlWebApplicationContext] Refreshing WebApplicationContext for namespace 'springmvc-servlet': startup date [Thu Jun 28 23:53:04 IST 2012]; root of context hierarchy
23:53:04,609 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/context/services-context.xml]
23:53:04,890 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6c4fe: defining beans [dummyService]; root of factory hierarchy
23:53:05,156 INFO [DispatcherServlet] FrameworkServlet 'springmvc': initialization completed in 750 ms
.....
.....
23:56:17,875 WARN [PageNotFound] No mapping found for HTTP request with URI [/springmvc/cgi/user] in DispatcherServlet with name 'springmvc'
当我单击 index.jsp 中的该链接时,我收到 404 错误。我觉得我可能犯了一个愚蠢的错误。但是,无法跟踪它。有人可以帮助我吗?