java - 为什么 pageContext.request.contextPath 被视为字符串而不是类路径?
问题描述
当我使用我的
<a href="${pageContext.request.contextPath}/rest/hello">Hello</a>
我的网址变成
http://localhost:8080/spring-rest-demo/$%7BpageContext.request.contextPath%7D/rest/hello
为什么会这样
我的 pom 文件中也有 javax.servlet-api 和 javax.servlet.jsp-api 依赖项
它是一个jsp文件而不是html
解决方案
Expressions like ${pageContext.request.contextPath} cannot be used in a plain HTML file, they must be used inside a JSP file. I suggest you start by reading a few tutorials about Java servlets and JSP.
You can simply ignore it.
If you really want to redirect it to another page. So, you need to add JSTL Dependency
to use the expression language.
I recommend you to use Thymeleaf
which is easy to use and you can easily play with the controller's
推荐阅读
- mongodb - 错误:未捕获(承诺中)AssertionError
- amazon-sagemaker - 如何编辑 Sagemaker 标签快捷方式选项卡?
- flutter - Flutter 是否可以制作 IOS 搜索栏 ui?如何?
- pandas - 如何检索 Pandas-datareader 发送的确切 API 查询
- lucene - 删除 Lucene 索引并让它们稍后自动重新创建是否安全?
- arrays - Perl 嵌套哈希匹配和合并
- python - 无法用 Pandas 确定 Excel 文件格式,随机发生
- flutter - 在颤动中实现这种布局
- android - 我们可以从 Android Surface 获取文件描述符吗?
- push-notification - 在 swift 应用程序中点击推送消息时打开视图