如何使用EL访问导入对象的静态字段

时间:2011-04-04 17:32:51

标签: jsp variables scope el

  

可能重复:
  How to reference constants in EL?

假设我有一个static final int字段的类,我在jsp页面中导入了一个类:

<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="UTF-8"%>
<%@ page import="com.mycompany.Object" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
    The static field with EL is: ${Object.STATIC_FIELD} <br />
    The static field with Scriptlet is: <%=Object.STATIC_FIELD%> <br />
    El and pageScope (doesnt work either): ${pageScope.Object.STATIC_FIELD}
</body>
</html>

使用scriptlet进行访问,但不能使用EL。

0 个答案:

没有答案