在DispatcherServlet中找不到带有URI [/ FirstSpringApp /]的HTTP请求的映射,其名称为' spring-dispatcher'

时间:2015-03-18 02:01:17

标签: java spring jsp spring-mvc servlets

所以你好,我试图从其他命题中找到我的代码的解决方案但是徒劳:/所以这是我的代码寻求帮助:/ 弹簧调度-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>

的LoginController

 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>

3 个答案:

答案 0 :(得分:0)

@Controller
@RequestMapping(value="/FirstSpringApp")
public class LoginController {
    ....
}

答案 1 :(得分:0)

  1. 使用<url-pattern>/</url-pattern>替换<url-pattern>/*</url-pattern>
  2. 更改后缀&#34; .jsp&#34;到&#34; .html&#34;
  3. 只需设置@RequestMapping(value="/admissionForm", method = RequestMethod.GET)
  4. 即可

答案 2 :(得分:0)

您在Web.xml文件中将FirstSpringApp映射到哪里?我想,创建的网址是http://<IP>:<PORT>/<CONTROLLER_URL>

例如:

http://localhost:9090/submitAdminssionForm