[英]<c:foreach> doesn't seem to work
I've seen all similar questions but I didn't find any working answer to my issue. 我已经看过所有类似的问题,但没有找到解决此问题的有效方法。
Simple jsp file: 简单的jsp文件:
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<% String[] names = {"Jhn", "Kate", "Larry"};
pageContext.setAttribute("myNames", names);
%>
<html>
<body>
<c:forEach var="tempName" items="${myNames}">
<p>${tempName}</p>
</c:forEach>
</body>
</html>
Maven dependencies: Maven依赖项:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>javax.servlet.jsp-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
The output of JSP file is JSP文件的输出是
${tempName}
Though, I expect 虽然,我希望
Jhn
Kate
Larry
I feel like I am missing something but can't find out what's wrong. 我觉得自己正在丢失某些东西,但找不到错误所在。
Edit: I'd like to mention that if I create a dynamic web app and do the same things(except maven dependencies, obviously) - it works perfectly but as soon as I create maven project - it stops to work 编辑:我想提一下,如果我创建一个动态Web应用程序并执行相同的操作(显然,除了maven依赖项以外),它可以正常工作,但是一旦创建了maven项目,它就会停止工作
Well, that is absolutely ridiculous. 好吧,那绝对是荒谬的。 It began to work and I changed nothing to make it work.
它开始起作用,我没有做任何改变使其起作用。
The only things I've done are: 我唯一要做的是:
Added to web.xml into web-app tag: 将web.xml添加到web-app标签中:
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd"
version="2.4"
then deleted it 然后删除它
After I changed 我改变之后
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
to 至
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
and then back to 然后回
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
Technically, nothing changed. 从技术上讲,什么都没有改变。 But somehow it began to work.
但是它以某种方式开始起作用。 I have no idea what happened.
我不知道发生了什么事。
Though, in other similar projects it still doesn't work. 但是,在其他类似项目中,它仍然无法正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.