【问题标题】:JSTL tag doesn't work in my jspJSTL 标记在我的 jsp 中不起作用
【发布时间】: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

enter image description here

我的 .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


【解决方案1】:

&lt;c:out&gt; 打印你想要的值,你不需要引用它然后调用它,你用括号 () 做,当你调用一个 jstl 变量时,你使用花括号 {}

<body>
  <c:set var="vehicle" value="car"></c:set>
  <h1><c:out value="${vehicle}"/></h1>
 </body>

【讨论】:

  • 是的,我更正了你的建议,但错误仍然存​​在,我把我的问题放在我的 stucture 文件夹中
猜你喜欢
  • 2018-12-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多