【问题标题】:No mapping for GET /springMVC/form.jspGET /springMVC/form.jsp 没有映射
【发布时间】:2019-09-27 13:54:10
【问题描述】:

我正在尝试使用 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 没有映射

【问题讨论】:

  • 你用什么网址做主页链接?
  • localhost:8080/springMVC/ 这是我的主页

标签: spring spring-mvc


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 仍然无法正常工作,我收到相同的消息: 说明 源服务器没有找到目标资源的当前表示或不愿意透露存在的表示。 -------------------------------------------------- ------------------------------
    • 问题标题和问题描述中的错误消息不同..请确认哪个是确切的错误消息 No mapping for GET /springMVC/form.jsp 或 No mapping for GET / springMVC/showForm
    • “No mapping for GET /springMVC/showForm”消息来自控制台,并且“描述源服务器没有找到目标资源的当前表示或不愿意透露存在的表示" 来自屏幕
    • 我创建了新项目,而不是动态战争项目,我创建了 maven 战争项目,并且成功了。
    【解决方案3】:

    我不知道它是如何工作的,但是我将我的项目切换为 maven war 项目而不是 Dynamic web app,问题就解决了。谁能解释一下?

    【讨论】:

      猜你喜欢
      • 2020-07-30
      • 2020-01-05
      • 2012-02-04
      • 2020-01-08
      • 1970-01-01
      • 1970-01-01
      • 2021-04-29
      • 2013-06-13
      • 1970-01-01
      相关资源
      最近更新 更多