当前位置:网站首页>服务器响应未加载静态资源
服务器响应未加载静态资源
2022-06-09 20:43:00 【w_rcss】
有个兄弟今天问了我一个问题:
页面不加载css。
思路:页面不加载css先排除页面本身的代码问题,经过检查,代码没有问题,单独打开页面测试发现可以正常加载css,判断为服务器响应没有加载静态资源。
先说解决方案:
web.xml文件中添加:
<mvc:default-servlet-handler/>
问题完美解决。
详解:
web.xml配置如下:
<servlet>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
spring通过DispatcherServlet捕获所有请求,但是只能处理普通请求,静态资源的请求会因为找不到相对应的处理器而报错。在web.xml中添加:
<mvc:default-servlet-handler/>
通过配置default-servlet-handler会生成一个DefaultServletHttpRequestHandler对象,该对象检查所有请求,非静态资源请求交DispatcherServlet处理,静态资源请求由服务器默认Servlet处理,以此来解决springmvc不好处理静态资源请求的问题。
如此,springmvc便可以很好的工作了。
边栏推荐
- Usage of memberwiseclone in C #
- GameFi新的启程,AQUANEE将于6.9日登陆Gate以及BitMart
- 关于C#Unity读写文件
- Inheritance relationship in C #
- C#中的里氏替换原则
- Jerry's Bluetooth distribution network [chapter]
- [tgowt] cmake to Ninja construction
- C interface class learning
- Integer ordered array lookup -- traversal and half / bisection
- Apply for software code signing certificate
猜你喜欢

ClickHouse 数据插入、更新与删除操作 SQL

Gamefi's new departure, aquanee will log in to gate and bitmart on June 9

源代码数据防泄露解决方案分析
![[database data recovery] SQL Server database data recovery case](/img/82/99d3135b6f412a532444e80c2d7faa.jpg)
[database data recovery] SQL Server database data recovery case

C language to realize computer automatic shutdown program -- it can be used to spoof roommate's computer

Changshu science and technology applet SQL injection

Apple Announces Winner of the 2022 Apple Design Award

Edge browser setting network speed limit

Xcode 14 brings new improvements, and Xcode cloud is officially launched!

C language implementation of simple calculator
随机推荐
minikube config set driver kvm2
关于C#Unity读写文件
【mysql】主从复制原理、搭建
Kubernetes原生CICD:Tekton hello-world
Huawei's cloud industrial intelligence hub provides new momentum for accelerating the upgrading of industrial intelligence
Charles grabbing iPhone
C#接口类的学习
部署 cinder-csi-plugin 遇到的几个问题
部署 Kubernetes + KubeVirt 以及 KubeVirt的基本使用
LeetCode 497. 非重叠矩形中的随机点**
C# For循环的一些小细节
C#中的里氏替换原则
内卷大厂系列《线段树-会议室问题》
源代码数据防泄露解决方案分析
华为云Stack首席架构师:打造“称手”的数字化工具,答好政企IT数字化转型这道必选题
Vite Lerna Monorepo 项目改造初体验
TypeScript 变量声明
SSL (secure socket layer) digital certificate
Neo4j桌面版數據庫備份
(上)苹果有开源,但又怎样呢?