Я получаю WARN PageNotFound: 1136 - Не найдено сопоставление для HTTP-запроса с URI [/ CATestSlotBooking / show] в DispatcherServlet с именем «spring», когда я нажимаю любую ссылку из welcome.jsp.
Нижекласс контроллера
@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"; }
Сервлет-диспетчер 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. Если я изменю шаблон URL на / * или * .do в web.xml, я не получу страницу welcome.jsp.
Удалить <welcome-file-list> из файла 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>