【发布时间】:2018-12-23 17:15:37
【问题描述】:
我创建了一个 maven 项目,我必须使用 JSTL。
问题是当我导入库时它不起作用。我想设置一个变量,然后我想显示值。
这是我的jsp页面:
<body>
<c:set var="vehicle" value="car"></c:set>
<c:out value="${vehicle}"></c:out>
<h1>$(vehicle)</h1>
</body>
问题是我没有显示值“car”,但我阅读了 ${vehicle}。
我认为是一个问题或依赖。所以我的 pom.xml 是这样的:
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</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>javax.servlet-api</artifactId>
<version>${servlet-api-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${jsp-version}</version>
<scope>provided</scope>
</dependency>
<!-- JSTL dependency -->
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>${jstl-version}</version>
</dependency>
谁能帮帮我?
编辑 这是我的结构文件夹。 D
我的 .jsp 代码
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="it.model.OggettoDaVendere" %>
<html>
<head>
<title>CRUD</title>
</head>
<body>
<c:set var="vehicle" value="car"></c:set>
<c:out value="${vehicle}"></c:out>
<h1>${vehicle}</h1>
</body>
</html>
web.xml 代码:
<web-app>
<display-name>Archetype Created Web Application</display-name>
<listener>
<listener-class>it.servlet.CRUDListener</listener-class>
</listener>
<servlet>
<servlet-name>CRUDServlet</servlet-name>
<display-name>CRUDServlet</display-name>
<description></description>
<servlet-class>it.servlet.CRUDServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CRUDServlet</servlet-name>
<url-pattern>/CRUDServlet</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
【问题讨论】:
-
添加你的jsp文件的完整代码和
web.xml -
@lucumut 我编辑我的问题
-
你可以看到这个stackoverflow.com/questions/7579735/why-jstl-is-not-working还有你的
web.xml不包括servlt版本,我说的是full code,你不要添加它的完整代码 -
@lumacut 您发布给我的解决方案是有效的。我创建文件夹 webapp/WEB-INF/libs 并放入 jar jstl.jar 和 standard.jar。我有罐子来构建路径,但它不起作用。我的 .js 在 webapp/index.jsp 中。我如何修改我的 web.xml?
-
@lucumt 抱歉,该解决方案不起作用。我写错了!
标签: jsp servlets jakarta-ee jstl