spring-servlet.xml

 <bean id="viewResolver"
            class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
          <property name="prefix" value="/WEB-INF/" />
            <property name="suffix" value=".jsp" />
     </bean>


控制器类

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

            ModelAndView model = new ModelAndView("AdmissionForm");

            return model;
        }
        @RequestMapping(value="/admissionForm.jsp", method = RequestMethod.GET)
        public ModelAndView getAdmissionForm2() {

            ModelAndView model = new ModelAndView("AdmissionForm");

            return model;
        }
        @RequestMapping(value="/admissionForm", method = RequestMethod.GET)
        public ModelAndView getAdmissionForm3() {

            ModelAndView model = new ModelAndView("AdmissionForm");

            return model;
        }


web.xml

 <servlet>
    <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>
                  org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <load-on-startup>1</load-on-startup>
  </servlet>

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


每当我通过/admissionForm.html和/ admissionForm访问url时
我在网页中得到响应,但是当我通过/admissionForm.jsp访问时却找不到404页面,我的问题是这是什么原因,我能做些什么来使它起作用?

最佳答案

在web.xml文件中更改

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

关于java - Spring的RequestMapping如何工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33956020/

10-13 03:41