我收到WARN PageNotFound:1136-当我单击来自welcome.jsp的任何链接时,在DispatcherServlet中未找到具有URI [/ CATestSlotBooking / show]的HTTP请求的映射,名称为“ spring”。
下面是控制器类
@Controller
public class BookingSlotController {
@RequestMapping(value = "/show", method = RequestMethod.GET)
public String showBookingPage(ModelMap model) {
BookingSlotVO bookingDetailsVO = new BookingSlotVO();
model.addAttribute("bookingSlotVO", bookingDetailsVO);
return "booking";
}
分派器Servlet MXL
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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:annotation-config />
<context:component-scan base-package="com.cts" />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="localeResolver" class="org.springframework.web.servlet.i18n.SessionLocaleResolver">
<property name="defaultLocale" value="en" ></property>
</bean>
<mvc:interceptors>
<bean id="localChangeInterceptor" class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
<property name="paramName" value="lang" />
</bean>
</mvc:interceptors>
</beans>
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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>OnlineTestSlotBooking</display-name>
<welcome-file-list>
<welcome-file>Welcome.html</welcome-file>
<welcome-file>Welcome.htm</welcome-file>
<welcome-file>Welcome.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
welcome.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome page</title>
</head>
<body>
<p> CA Enablement Assessments </p>
<hr>
<a href="show">Book a slot for assessment</a>
<div style="text-align: right; background-color: yellow ">
<a href="${pageContext.request.contextPath}/show?lang=en" >Login(English)
</a>
<a href="${pageContext.request.contextPath}/show?lang=es" >Login(Spanish)
</a>
</div>
</body>
</html>
当我单击welcome.jsp中的任何链接时,出现404错误。如果将web.xml中的URL模式更改为/ *或* .do,则不会显示welcome.jsp页面。
最佳答案
从web.xml中删除<welcome-file-list>
。
更新后的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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>OnlineTestSlotBooking</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
关于java - PageNotFound:1136-在DispatcherServlet中找不到名称为“spring”的HTTP请求的URI []映射,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58299445/