我已經在採用以下方式配置尋址使用Spring MVC的應用春3.1.1.RELEASE請求不被彈簧控制器
的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"/>
UserController.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";
}
}
的index.jsp
<a class="action" href="cgi/user">Default Action</a>
Sever的日誌上用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.s[email protected]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錯誤。我可能犯了一個愚蠢的錯誤。但是,無法跟蹤它。有人可以幫助我嗎?
嘗試將'@RequestMapping(value =「/」,method = RequestMethod.GET)'on defaultRequest()' –