【问题标题】:JSP cant find request attributes set in Servlet when using JSTL [duplicate]使用JSTL时,JSP找不到在Servlet中设置的请求属性[重复]
【发布时间】:2019-05-12 19:30:01
【问题描述】:

当我尝试使用 JSTL 时,JSP 无法识别我通过 servlet 提供的数据。我可以在 JSP 中使用 Java 代码访问请求属性,但不能使用 JSTL。

我正在使用 tomcat 服务器。我尝试在使用 maven 时更改 pom xml 中的一些依赖项。 现在我用的是1.2版本的jstl。

来自 pom.xml

<dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
            <scope>runtime</scope>
        </dependency>
...

来自 servlet

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String data = "Some data, can be a String or a Javabean";
        request.setAttribute("data", data);
        request.setAttribute("userList", users);
        RequestDispatcher rd = request.getRequestDispatcher("/DisplayUsers.jsp");
        rd.forward(request, response);
    }
...

来自位于 webapp 文件夹中的 .jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<html>
<head>
    <title>Alle gespeicherten Nutzer</title>
    <meta content = "text/html; charset = UTF-8"/>
</head>
<body>
<% String name = request.getAttribute("data").toString(); //this works
out.print(""+name);
%>
<p>The data from servlet: ${data}</p> // THIS DOESN´T recognize data

预期输出:来自 servlet 的数据:一些数据,可以是字符串或 Javabean 实际输出:来自 servlet 的数据:${data}

【问题讨论】:

    标签: java jsp servlets jstl


    【解决方案1】:

    试试这个jsp的导入
    的位置 这一个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-09
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 2014-06-22
      相关资源
      最近更新 更多