最近感觉基础知识有点模糊了,反过头来重新温故一下。果然遇到了问题。
在jsp页面上从作用域中获取值时,使用el表达式获取无效。
jdk:1.8.0_131
tool:eclipse mars2
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setAttribute("num", 4);
%>
${num}
</body>
</html>
jsp如以上代码,按道理说页面直接输出4.但是结果为
${num}
说明并没有获取到值。
查询了资料才知道是web.xml中servlet版本是2.3,版本过低,需要配置page内置对象的isELIgnore属性值为false,打开el表达式解析。
servlet 2.4版本的isELIgnore属性值默认是false。2.5版本默认也是关闭的。
修改后代码如下:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setAttribute("num", 4);
%>
${num}
</body>
</html>