没有get /springmvc/form.jsp的映射



我正在尝试与Spring MVC一起工作。我的问题是我的控制器中没有请求映射工作,只有我的主页链接:"/"正在工作。

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

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

我的web.xml文件是:

<?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>

和我的spring-mvc-demo-servlet.xml是:

<?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>

每当我尝试到达showform的链接时,我都会得到此消息:

2019年5月9日4:55:42 org.springframework.web.servlet.dispatcherservlet nohandlerfound警告:get/springmvc/showform

无映射

我遇到了同样的问题,我做了以下操作:清洁您的项目:在Eclipse中,去项目 ->清洁右键单击项目并刷新它。

尝试通过添加URL和方法类型的值将方法更改为下面。

@RequestMapping(value="/showForm", method=RequestMethod.GET)

我不知道它是如何工作的,但是我将项目切换到Maven War Project而不是动态的Web应用程序中,并且解决了问题。如果有人可以提供任何解释?

最新更新