JSTL 标签库问题
我有一个简单的 Maven Web 项目。我就是想不出让 JSTL 标签工作的方法。 出于测试目的,我创建了一个没有任何依赖项的虚拟项目,除了:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
在我的 JSP 页面中,我有以下测试代码 -
<c:set var="hello" value="see this?"/>
<c:out value="${hello}"></c:out>
<h2>${hello}</h2>
<br/>
<%=request.getAttribute("hello") %>
我还在顶部包含了 jstl 声明 - <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
但是,这似乎不起作用。令人惊讶的是,${hello}
没有显示任何有意义的内容,但 request.getAttribute...
却显示了。这意味着 c:set
实际上正在工作,而 c:out
和简单表达式都不起作用。我在这里错过了什么吗?
感谢您的帮助——三天来我一直在努力解决这个问题!
I have a simple maven web project. I simply can't figure out a way to have the JSTL tags work.
For testing purposes, I've created a dummy project having no dependency except for:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
in my JSP page, I have the following test code -
<c:set var="hello" value="see this?"/>
<c:out value="${hello}"></c:out>
<h2>${hello}</h2>
<br/>
<%=request.getAttribute("hello") %>
I have also included the jstl declaration on the top -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
However, this does not seem to work. Surprisingly, the ${hello}
doesn't show anything meaningful, but the request.getAttribute...
does. This means that the c:set
is actually working, and both the c:out
and simple expression do NOT work. Am I missing out something here?
Any help is appreciated - been trying to get my head around this for 3 days now!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JSTL jar 仅包含规范的标准类和接口,但没有标签的实现。
将此依赖项添加到您的 pom 中:
顺便说一句,请始终查看生成的 HTML 代码以了解发生了什么。并且
c:set
标记设置 page 范围属性,而不是 request 范围属性,因此request.getAttribute( "hello")
输出的内容与之前放置的c:set
标记无关。The JSTL jar only contains the standard classes and interfaces of the spec, but no implementation for the tags.
Add this dependency to your pom :
BTW, always look at the generated HTML code to see what's going on. And the
c:set
tag sets a page scope attribute, not a request scope attribute, so the fact thatrequest.getAttribute("hello")
outputs something doesn't have anything to do with thec:set
tag placed before.解决方案在于查看 StackOverflow 中提供的 JSTL 信息文档。它几乎提到了有关 JSTL 安装为何无法正常工作的所有信息。
The solution lies in checking out the info document on JSTL provided within StackOverflow. It mentions almost everything there is to know about why your JSTL installation may not be working properly.