EL表达式
程序员文章站
2022-04-07 14:53:40
...
<%@page import="java.util.Date"%>
<%@page import="web1.Customer"%>
<%@ 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>
<form action="el1.jsp" method="post">
username:<input type="text" name="username"
value="<%=request.getParameter("username") == null ? "" : request.getParameter("username")%>" />
<br>
<br>
<!--回显 -->
username:<input type="text" name="username" value="${param.username}" />
<input type="submit" value="Submit" />
</form>
username:<%=request.getParameter("username")%>
<br>
<jsp:useBean id="customer" class="web1.Customer" scope="session"></jsp:useBean>
<jsp:setProperty property="id" value="12" name="customer" />
id:<%
Customer customer3 = (Customer) session.getAttribute("custoemr");
out.print(customer3);
%>
<br>
<!-- 换个页面不能输出 -->
<jsp:getProperty property="id" name="customer" />
<a href="el2.jsp?score=23&name=A&name=B&name=C">To EL2 Page</a>
<%
application.setAttribute("time", new Date());
%>
</body>
</html>
<%@page import="web1.Customer"%>
<%@ 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>
<!-- 7.EL运算符 -->
${param.score>60 ? "及格":"不及格" }
name is empty${empty requestScope.names }
<!--6 其他隐含对象 pageContext等 (cookie,header,initParam了解)
pageContext:pageContext既为pageContext类型 但只能读取属性值就可以一直点下去
-->
<br> contextpath: ${pageContext.request.contextPath }
<br>queryString: ${pageContext.request.queryString }
<br> sessionid: ${pageContext.session.id }
<br>
<br> sessionAttributeNames: ${pageContext.session.attributeNames }
<br> initParam: ${initParam.initName }
<br> Accept-Language: ${header["Accept-Language zh-CN"] }
<br>
<!-- 5 于输入有关的隐含对象 param paramValues -->
score3:${param.score }
<br>
<%=request.getAttribute("scope")%>
<!-- 不能遍历 有get方法的话可以一直点下去-->
<br> names:${paramValues.name[0]["class"]}
<%--=request.getParameterValues("name")[0].getClass().getName() --%>
<!--4 隐含对象之域范围相关的 pageScope,requestScope,sessionScope,applicationScope -->
<br> time:${applicationScope.time }
<br>
<%=application.getAttribute("time")%>
<!-- -->
<!-- el可以自动类型转换 在el1输出 -->
score:${param.score+11 } =100 score2:<%=request.getParameter("score") + 11%>
=8911
<!-- el中的隐含变量 -->
<%
Customer c1 = new Customer();
c1.setId(49);
request.setAttribute("customer", c1);
%>
<br> id2:${customer.id }
<!-- session范围内有一个customer 有一个age属性 相当与以下代码 -->
<br> id:${sessionScope.customer.id }
<br> id:${sessionScope.customer["id"] }
<br> id:<%
Customer customer3 = (Customer) session.getAttribute("custoemr");
out.print(customer3);
%>
<%
Customer c = new Customer();
c.setAddress("shanxi");
session.setAttribute("com.greatest.customer", c);
%>
<!-- 如果域对象中的书姓名 带有特殊字符 则使用[]运算符会很方便 -->
address:${sessionScope["com.greatest.customer"].address}
</body>
</html>