问题
可以看到${pageContext.request.contextPath}没有正确获取路径而是出现了乱码
解决
出现这个问题一种情况是没有导入servlet和jsp的jar,所以我们需要导入servelt和jsp的jar。另外一种情况是web.xml文件中的web-app版本过低导致,只有2.4及以上版本才可以正确显示,以下给出了对应情况的解决方法,判断自己是哪一种情况,然后解决即可。
servlet和jsp的依赖
复制代码
1
2
3
4
5
6
7
8
9
10
11
12<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> </dependency>
web.xml文件的头
复制代码
1
2
3
4
5
6<?xml version="1.0" encoding="UTF-8"?> <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> </web-app>
最后
以上就是高挑机器猫最近收集整理的关于使用${pageContext.request.contextPath}时无法解析而乱码的解决的全部内容,更多相关使用${pageContext.request.contextPath}时无法解析而乱码内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复