下面介绍 EL 表达式中常量与变量的定义和用法。
EL 表达式中的常量也称为字面常量,它是不可改变的数据。EL 表达式中有以下几种常量。
【例1】常量的使用(symbol_const_demo.jsp):
<%@ page contentType="text/html" pageEncoding="utf-8" %>
<html>
<head>
<title>EL 中的符号常量</title>
</head>
<%
String color="#66FFFF";
String size="12";
String textclr="Blue";
String foregr="Red";
pageContext.setAttribute("color",color);
pageContext.setAttribute("size",size);
pageContext.setAttribute("textclr",textclr);
pageContext.setAttribute("foregr",foregr);
%>
<body bgcolor="${ pageScope.color }"
text="${ pageScope.textclr }">
<h1>EL 中的符号常量的用法</h1>
<Font color="${ pageScope.foregr }"
size="${ pageScope.size }">
背景色和文本颜色已经修改
</Font>
<br/>
</body>
</html>
程序运行结果如图 1 所示。