首页 > 解决方案 > No mapping for GET /springMVC/form.jsp

问题描述

I'm trying to work with spring mvc. My problem is that no request mapping is working in my controller, only my home page link: "/" is working.

@Controller
public class HelloWoldController {

     @RequestMapping("/")
    public String showPage() {
        return "main";
    }


    @RequestMapping("/showForm")
    public String showForm() {
        return "form";
    }

}

my web.xml file is:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>springMVC</display-name>


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

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

</web-app>

and my spring-mvc-demo-servlet.xml is:

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

    <context:component-scan
        base-package="com.kaygi22.springmvc" />

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

Whenever I try to get to the link of showForm, i get this message:

May 09, 2019 4:55:42 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound WARNING: No mapping for GET /springMVC/showForm

标签: springspring-mvc

解决方案


我遇到了同样的问题,我做了以下事情:清理你的项目:在 Eclipse 中,转到 Project-->clean 并右键单击项目并刷新它。


推荐阅读