【发布时间】:2016-05-03 17:26:10
【问题描述】:
大家好,我一直在处理这个问题,但我在浏览时找不到解决方案,希望您能帮助我。无论我对控制器 web.xml 或 search-customer-context.xml 做了多少更改,我都会不断收到“HTTP 状态 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>
`
搜索客户上下文.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
@控制器 公共类 SearchController {
@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:
【问题讨论】:
-
HTTP 404 可能意味着断开/死链接。
/SearchCustomerID/welcome.jsp文件是否存在? -
文件存在于/WEB-INF/jsp文件夹中
标签: spring spring-mvc web.xml