EL 在 jsp 3.1 中不工作

EL is not working in jsp 3.1

我正在使用 eclipse mars, JDK8, Tomcat 8.

这是我的 JSP 页面

<%@page import="com.cutm.pogo.User"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>User Page</title>
<link href="css/nodue_style.css" rel="stylesheet" type="text/css" />
<%@ page isELIgnored="false" %>
........
<%  User user = (User)session.getAttribute("LOGIN");
    out.print(user.getName());      %>
${user.name }

我用过 out.print,它对我有用,但对 EL 没用。

这里是web.xml文件

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">

请帮忙找出我犯的错误。

试试这个,希望它有效:您需要使该变量可用于在 EL / JSTL 中访问它。所以使用 setAttribute,你可以设置值。

    <%
    User user = (User)session.getAttribute("LOGIN");
    pageContext.setAttribute("userobj", user);
    %>
    ${userobj.name}
    

您应该能够直接使用访问会话属性:

 ${sessionScope.LOGIN.name}

PS :我建议您永远不要将 Java 代码放入 JSP,因为存在 EL 和 JSTL。这将更具可读性;)