0
大家好我一直在處理這個問題,我找不到一個瀏覽解決方案,希望你能幫助我。無論我對控制器,web.xml或search-customer-context.xml進行了多少更改,我總是收到「HTTP狀態404 - /SearchCustomerID/search.jsp」。希望你能幫助解決這個問題。這是我的文件。 的web.xml使用Spring MVC處理請求
<?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
@Controller 公共類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文件夾中 –