首页 > 解决方案 > 为什么 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

标签: javaspringspring-mvcjspel

解决方案


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


推荐阅读