【问题标题】:PageNotFound:1136 - No mapping found for HTTP request with URI [] in DispatcherServlet with name 'spring'PageNotFound:1136 - 在名为“spring”的 DispatcherServlet 中找不到具有 URI [] 的 HTTP 请求的映射
【发布时间】:2019-10-09 07:52:31
【问题描述】:

当我单击welcome.jsp 中的任何链接时,我收到WARN PageNotFound:1136 - 在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";
}

Dispatcher 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>
&nbsp;&nbsp;
<a href="${pageContext.request.contextPath}/show?lang=es" >Login(Spanish) 
 </a>

</div>
</body>
</html>

当我单击welcome.jsp 中的任何链接时,我会收到404 错误。如果我在 web.xml 中将 URL 模式更改为 /* 或 *.do,我不会得到 welcome.jsp 页面。

【问题讨论】:

    标签: java spring-mvc jsp internationalization


    【解决方案1】:

    从 web.xml 中删除 &lt;welcome-file-list&gt;

    更新后的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>
    

    【讨论】:

    • 不,这也不起作用。 在名称为“spring”的 DispatcherServlet 中找不到带有 URI [/CATestSlotBooking/] 的 HTTP 请求的映射错误显示。
    • 你的项目名称是 CATestSlotBooking_Skeleton -> url 应该是/CATestSlotBooking_Skeleton/show
    • 作为服务器运行。然后,检查 Eclipse 为您创建的 url。
    • 我确实作为服务器运行,这是 Eclipse 生成的 URL“localhost:8088/CATestSlotBooking/”。但是 wlecome.jsp 页面没有显示。如果我将 URL 模式从 \* 更改为 \,则会显示welcome.jsp,但无法从欢迎页面继续。
    • 它在删除 后工作。非常感谢
    猜你喜欢
    • 2016-05-03
    • 2013-11-19
    • 1970-01-01
    • 1970-01-01
    • 2012-04-16
    • 1970-01-01
    • 2021-08-01
    • 1970-01-01
    • 2015-08-04
    相关资源
    最近更新 更多