简体   繁体   中英

No Mapping Found for HTTP Request in spring mvc

I'm getting a no mapping found for the dispatcher servelt. can you please point me where the issue is in the code. I'm very new to Spring MVC

My Error is (My pom has the artifactId of EnhancedRoyaltyTool)

No mapping found for HTTP request with URI [/EnhancedRoyaltyTool/] in DispatcherServlet with name 'mvc-dispatcher

My web.xml file

<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <display-name>Spring Web MVC Application</display-name>


    <servlet>
        <servlet-name>mvc-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>  




<!--    <listener> -->
<!--         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> -->
<!--     </listener>    -->
</web-app>

My mvc-dispatcher-servlet.xml file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.acxiom.saas.royalty.controller"/>

    <mvc:annotation-driven/>



    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/pages/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

</beans>

My Controller file

@Controller
public class SearchController 
{   

    @ModelAttribute("search")
    public Search getSearch()
    {
        return new Search();
    }


    @RequestMapping(value ="/")
    public String homePage()
    {
        System.out.println("home");     

        return "search";        
    }

    @RequestMapping(value ="/payRoyalties", method = RequestMethod.POST)
    public String searchJobs(ModelMap model, @ModelAttribute("search") Search search)
    {
        System.out.println(search.getOesNumber() +"TEST");
        model.addAttribute("test", "testing modelmap");

        return "payRoyalties";      
    }

}

my search.jsp file

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Search For Jobs</title>
</head>
<body>

    <form:form   method="POST" modelAttribute="search" action="payRoyalties"    >
        <table>
            <tr>
                <td><form:label path="oesNumber">OES Number</form:label></td>
                <td><form:input path="oesNumber" /></td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" value="Search" /></td>
            </tr>
        </table>

    </form:form>

</body>
</html>

I do have a payRoyalties.jsp file and Search model.

There is no mapping named search in your class.

You need to add @RequestMapping(value ="/search") before your getSearch() Method

I think the problem lies in your web servlet configuration. I have seen this case before, when Spring confuses between mapping URL with mapping to JSP files.

In short, instead of:

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

You should try:

 <servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/*.html</url-pattern>
</servlet-mapping>

Then try access your controller with /payRoyalties.html

@ModelAttribute("search")
public Search getSearch()
{
    return new Search();
}

Above part of your code is confusing, you have "search" in @ModelAttribute while there is no "search" for @RequestMapping, what are you trying to do with this.

please provide log for any more assistance.

You want this:

@Controller
@RequestMapping("/search")
public class SearchController {
    …
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM