[英]JSP cant find request attributes set in Servlet when using JSTL [duplicate]
当我尝试使用JSTL时,JSP无法识别我通过servlet提供给它的数据。 我可以在JSP中使用Java代码访问请求属性,但不能使用JSTL。
我正在使用tomcat服务器。 我尝试在使用Maven时更改pom xml中的某些依赖项。 现在我正在使用jstl的1.2版本。
从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的数据:一些数据,可以是String或Javabean实际输出:来自servlet的数据:$ {data}
试试这个导入的jsp
<%@页面contentType =“ text / html; charset = UTF-8” language =“ java”%>的位置这一个<%@页面pageEncoding =“ UTF-8” contentType =“ text / html; charset = UTF- 8“ trimDirectiveWhitespaces =” true“%>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.