- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在请求适当的 View 时,我不断收到 404 not found HTTP 响应。
这些是我的配置文件。
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<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>ssytem-ecommerce-prototype-view</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:appContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/mvc-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcherServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
mvc-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
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">
<annotation-driven></annotation-driven>
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="ma.pack.net.*"></context:component-scan>
<resources mapping="/resources/**" location="/resources/" />
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/view/" />
<beans:property name="suffix" value=".html" />
</beans:bean>
</beans:beans>
HomeController.java
package ma.pack.net;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class HomeController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home() {
return "entry";
}
}
entry.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<b>Hello, This is the Front Page</b>
</body>
</html>
我不知道我在哪里犯了错误,我尝试更改 Controller 映射的名称、页面名称、页面扩展名,但我一直得到相同的输出。
最佳答案
这允许将 DispatcherServlet 映射到“/
”(从而覆盖容器默认 Servlet 的映射),同时仍然允许容器默认 Servlet 处理静态资源请求。它配置了 DefaultServletHttpRequestHandler
URL 映射为“/**
”,且相对于其他 URL 映射的优先级最低。
此处理程序会将所有请求转发到默认 Servlet。因此,重要的是它在所有其他 URL HandlerMapping 的顺序中保持在最后。如果您使用 <mvc:annotation-driven>
就会出现这种情况;如果您要设置自己的自定义 HandlerMapping 实例,请务必将其 order 属性设置为低于 DefaultServletHttpRequestHandler 的值,即 Integer.MAX_VALUE
.
要使用默认设置启用该功能,请使用:
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
或者在 XML 中:
<mvc:default-servlet-handler/>
覆盖“/
”Servlet 映射的注意事项是,默认 Servlet 的 RequestDispatcher 必须按名称而不是按路径检索。 DefaultServletHttpRequestHandler 将尝试在启动时自动检测容器的默认 Servlet,使用大多数主要 Servlet 容器(包括 Tomcat、Jetty、GlassFish、JBoss、Resin、WebLogic 和 WebSphere)的已知名称列表。如果默认 Servlet 已自定义配置为不同的名称,或者如果正在使用默认 Servlet 名称未知的不同 Servlet 容器,则必须显式提供默认 Servlet 的名称,如下例所示:
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable("myCustomDefaultServlet");
}
}
或者在 XML 中:
<mvc:default-servlet-handler default-servlet-name="myCustomDefaultServlet"/>
mvc-config.xml
:<mvc:default-servlet-handler />
关于java - DispatcherServlet 未重定向到适当的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42070886/
我正在将 Spring Boot 应用程序从版本 1.5.6 升级到 2.1.1。当我启动应用程序时,它卡在这一行: INFO: Initializing Spring DispatcherServl
基本上我想将我的应用程序分成两部分。每个部分都有自己的安全内容和自己的 @Controller。 @Services 应该可以从两个部分访问。 所以我想,我应该得到 2 个 DispatcherSer
我正在 Eclipse 中使用 Spring boot、Java 8 制作 RESTful 服务。每当我尝试从 Postman(或任何其他地方)发送 HTTP 请求时,我都会收到 404 未找到代码。
我认为配置文件中缺少某些内容,但我看不到。 当我在浏览器中输入 --> localhost:8080/Procura/notifications --> 我在控制台中输入这个 -->org.sprin
我看到类似的问题并尝试将 URL 从/* 映射到/但它不起作用。我也尝试过直接从浏览器访问该 URL,但也不起作用。我是 Spring 新手,有人可以帮助我吗? Archetype C
大家好,因为这是我的 Controller 类,当我在 postman 中运行此应用程序时,它的显示状态为 200 ok。但是文件未读取,我如何将带有扩展名的文件名作为方法中的字符串参数传递?我缺少您
这在 stackOverflow 中是一个很常见的问题,但没有一个相同问题的主题能解决我的问题。 我们有一个使用 xml 配置的模板配置,但现在我们正试图摆脱它并开始使用 Java 配置。 所以我有一
这个问题在这里已经有了答案: Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request
这个问题在这里已经有了答案: Why does Spring MVC respond with a 404 and report "No mapping found for HTTP request
我一直在使用 Spring MVC 4/hibernate 4 和 Web flow 2.4 以及 Java 配置来构建应用程序。我使用 JUnits 构建和测试了服务和 daos,但在向应用程序添加
配置 Tomcat 7.0.47 上的 Servlet 3.0 Spring 3.1 问题 我有一个比较特殊的情况,我需要两个 DispatcherServlets : 一个处理资源请求,一个处理正常
Spring MVC 使用 DispatcherServlet 将控制路由到适当的 Controller 。但是过滤器在哪里适合流程?如果我指定一个过滤器来执行 session 管理或身份验证,过滤器
这是我用于 spring mvc 的当前配置: 1- web.xml: spring org.springframework.web.servlet.DispatcherServ
我正在使用 Spring 框架来编写 Web 服务应用程序。应用程序中没有 html 或 jsp 页面。它是纯粹的网络服务。 这是我的 Controller 类 @RequestMapping("/*
我收到消息“请求的资源 () 不可用。”当转到我使用 DispatcherServlet 映射的 url 时。以前,当我将映射设置为使用 .do 扩展名时,它可以工作,但是当我在没有扩展名的情况下进行
在请求适当的 View 时,我不断收到 404 not found HTTP 响应。 这些是我的配置文件。 web.xml ssytem-ecommerce-pro
我有一个带有 javascript UI 的 Spring MVC (v4.1.3) Web 应用程序。我已经实现了一个自定义 DispatcherServlet 并在 web.xml 中配置了相同的
我在我的 Controller 中使用了 request.getRequestDispatcher(url).forward(request, response) 方法!!我有麻烦了。 (我知道调度程
几天来我一直在与这条消息作斗争,无法弄清楚我错在哪里。 基本上我想做的是在我的服务中提供 json。我对返回 jsp 不感兴趣。 我请求的网址是 localhost/service/products/
Spring + Angular 文件上传。尝试上传另一个文件时出现 HTTP - 417 错误时只能上传文件。 在第一次上传后启动服务器后,在 tomcat 上我收到以下消息 - Framewo
我是一名优秀的程序员,十分优秀!