启用 Spring MVC 处理请求

Enable with Spring MVC handling requests

大家好我一直在处理这个问题,我找不到解决方案浏览希望你能帮助我。无论我对控制器 web.xml 或 search-customer-context.xml 做了多少更改,我都会收到 "HTTP Status 404 - /SearchCustomerID/search.jsp"。希望你能帮助解决这个问题。这是我的文件。 web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Search Customer ID</display-name>
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <!-- <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/search-customer-servlet.xml</param-value>
</context-param> -->
    <servlet> 
        <servlet-name>search-customer</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>search-customer</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>
     <!--<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/search-customer-context.xml</param-value>
    </context-param>
    <listener>
       <listener-class>
           org.springframework.web.context.ContextLoaderListener
       </listener-class>
    </listener>  -->
</web-app>

`

搜索客户-context.xml

<beans xmlns="http://www.springframework.org/schema/beans"
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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
    http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">
<context:component-scan base-package="com.example.*" />
</bean>
     <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/WEB-INF/jsp/"/>
        <property name="suffix" value=".jsp" />
    </bean>

SearchController.java

@控制器 public class 搜索控制器 {

@RequestMapping("/SearchCustomerID/search")
public String searchInformation(@Valid @ModelAttribute("userInfo") UserInfo userInfo){
    System.out.println("Controller reached");
    System.out.println("Name: "+userInfo.getName());
    return "search";
}

}

jsp:

对不起大家我的错。问题是我已经将 web.xml 配置为 <url-pattern> 设置为 *html 但我的请求始终是 *.jsp 所以显然我不匹配。现在我更改了 URL 并且我能够通过注释为 Controller 的 class。