Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring MVC - No mapping found for request URI?

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!

like image 306
Gmx Avatar asked Sep 30 '22 05:09

Gmx


2 Answers

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>
like image 80
sankar Avatar answered Oct 04 '22 21:10

sankar


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.

like image 37
Tobías Avatar answered Oct 04 '22 21:10

Tobías