I get some problem using spring MVC Here is my web.xml config
<!-- config spring -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml,
/WEB-INF/classes/xfire-servlet.xml,
/WEB-INF/classes/mvc-servlet.xml,
classpath:org/codehaus/xfire/spring/xfire.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>
org.springframework.web.util.IntrospectorCleanupListener
</listener-class>
</listener>
<!-- spring mvc -->
<servlet>
<servlet-name>mvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
My controller is following
@Controller
@RequestMapping("/searchCase.do")
public class SearchCaseController {
public String getCaseDetailInfo() {
return "forward:caseDetail";
}
}
and my mvc config is
<!--auto scan annotation -->
<context:component-scan base-package="com.thunisoft.shxt.webservice.model.searchCase.logic" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/case" />
<property name="suffix" value=".jsp" />
</bean>
Then I request through the url:http://{address:port}/{application-name}/searchCase.do,But it can't find the controller to resolve my request with
No handler found in getLastModified
DispatcherServlet with name 'mvc' processing request for [/{application-name}/searchCase.do]
No mapping found for HTTP request with URI [/{application-name}/searchCase.do] in DispatcherServlet with name 'mvc'
Successfully completed request
My spring MVC version is 2.5.6 I'm waiting for your questions to help me solve this problem,thank you!
Please change the controller URL pattern as I mentioned below
.do will gets appended automatically to all controller request mapping since you configured in web.xml
@Controller
@RequestMapping("/searchCase")
public class SearchCaseController {
public String getCaseDetailInfo() {
return "forward:caseDetail";
}
}
JSP Code :
<a href="/searchCase.do">Click</a>
Try adding a method level annotation like this:
@Controller
@RequestMapping("/searchCase")
public class SearchCaseController {
@RequestMapping(method = RequestMethod.GET)
public String getCaseDetailInfo() {
return "forward:caseDetail";
}
}
Like it's described in the docs: Mapping Requests With @RequestMapping
17.3.2 Mapping Requests With @RequestMapping
You use the
@RequestMapping
annotation to map URLs such as/appointments
onto an entire class or a particular handler method. Typically the class-level annotation maps a specific request path (or path pattern) onto a form controller, with additional method-level annotations narrowing the primary mapping for a specific HTTP method request method ("GET", "POST", etc.) or an HTTP request parameter condition.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With