【问题标题】:No mapping found for HTTP request with URI [/FirstSpringApp/] in DispatcherServlet with name 'spring-dispatcher' [duplicate]在名称为“spring-dispatcher”的 DispatcherServlet 中找不到具有 URI [/FirstSpringApp/] 的 HTTP 请求的映射 [重复]
【发布时间】:2015-03-18 02:01:16
【问题描述】:

大家好,我试图从其他命题中为我的代码找到解决方案但徒劳无功:/所以这是我的代码寻求帮助:/ spring-dispatcher-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    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">


   <context:component-scan base-package="com.pfa.controller" />
   <mvc:annotation-driven/>
   <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
    <property name="prefix">
        <value>/WEB-INF/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>

</beans>

Web.xml

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

  <display-name>FirstSpringApp</display-name> 
  <servlet>
     <servlet-name>spring-dispatcher</servlet-name>
      <servlet-class>
              org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
  </servlet>

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

  </web-app>

登录控制器

 package com.pfa.controller;

import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.portlet.ModelAndView;

@Controller

public class LoginController {
@RequestMapping(value="/admissionForm.html", method = RequestMethod.GET)
public ModelAndView getAdmissionForm() {

    ModelAndView model = new ModelAndView("AdmissionForm");

    return model;
 }


   @RequestMapping(value="/submitadmissionForm.html", method =   RequestMethod.POST)
   public ModelAndView submitAdmissionForm(@RequestParam Map<String,String>  reqPar) {

    String name = reqPar.get("studentName");
    String hobby = reqPar.get("hobby");

    ModelAndView model = new ModelAndView("AdmissionSuccess");
    model.addObject("msg","Details submitted by you:: Name: "+name+ ",   Hobby: " + hobby);

    return model;
    }

 }

AdmissionForm.html

<html>
<body>
 <h1> STUDENT ADMISSION FORM FOR ENGINEERING COURSES</h1>

 <form action="/FirstSpringApp/submitadmissionForm.html" method="post">
    <p>
        Student's Name : <input type="text" name="studentName" />
    </p>
    <p>
        Student's Hobby : <input type="text" name="studentHobby" />
    </p>
    <input type="submit" value="Submit this form by clicking here" />
</form>

</body>
</html>

AdmissionSucces.html

 <html>
 <body>
 <h1>Congratulations!! the Engineering college has processed your      Application form successfully</h1>

<h2>${msgddd}</h2>

</body>
</html>

【问题讨论】:

  • 您要访问哪个网址?在您的问题中发布来自 Spring in 的确切日志消息。
  • 编辑您的问题。不要发布不是答案的答案。

标签: java spring jsp spring-mvc servlets


【解决方案1】:
@Controller
@RequestMapping(value="/FirstSpringApp")
public class LoginController {
    ....
}

【讨论】:

    【解决方案2】:
    1. 使用&lt;url-pattern&gt;/&lt;/url-pattern&gt;替换&lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    2. 将后缀“.jsp”更改为“.html”
    3. 只需设置@RequestMapping(value="/admissionForm", method = RequestMethod.GET)

    【讨论】:

      【解决方案3】:

      您在 Web.xml 文件中将 FirstSpringApp 映射到了哪里?我猜,正在创建的 URL 是 http://&lt;IP&gt;:&lt;PORT&gt;/&lt;CONTROLLER_URL&gt;

      例如:

      http://localhost:9090/submitAdminssionForm

      【讨论】:

      • 其实我在这里映射了 firstSpringAPP:@Controller @RequestMapping(value="/FirstSpringApp") public class LoginController { @RequestMapping(value="/admissionForm", method = RequestMethod.GET.... }我认为 url 应该是 localhost:9000/FirstSpringApp/submitAdmissionForm 。当我尝试执行 AdmissionForm.jsp 时,我发现更令人困惑的是我无法得到它!:(
      猜你喜欢
      • 2015-08-04
      • 1970-01-01
      • 2016-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多