EL運(yùn)算符:
%@page language="java" contentType="text/html;charset=gb2312"%>
%@page import="java.sql.*" %>
!DOCTYPE html>
html>
head>
title>El算數(shù)運(yùn)算符/title>
/head>
body>
table border=1>
tr>
td>算數(shù)運(yùn)算符/td>
td>結(jié)果/td>
/tr>
tr>
td>加法運(yùn)算符\${1 + 1}/td>
td>結(jié)果${1+1}/td>
/tr>
tr>
td>減法運(yùn)算符\${1 - 1}/td>
td>結(jié)果${1-1}/td>
/tr>
tr>
td>乘法運(yùn)算符\${1 * 2}/td>
td>結(jié)果${1 * 1}/td>
/tr>
tr>
td>除法運(yùn)算符\${3 / 2}/td>
td>結(jié)果${3 / 2}/td>
/tr>
tr>
td>求余運(yùn)算符\${3 % 2}/td>
td>結(jié)果${3 % 2}/td>
/tr>
/table>
table border=1>
tr>
td>關(guān)系運(yùn)算符/td>
td>結(jié)果/td>
/tr>
tr>
td>等于運(yùn)算符\${1 == 1}/td>
td>結(jié)果${1==1}/td>
/tr>
tr>
td>不等于運(yùn)算符\${1 != 1}/td>
td>結(jié)果${1!=1}/td>
/tr>
tr>
td>小于運(yùn)算符\${1 lt; 2}/td>
td>結(jié)果${1 2}/td>
/tr>
tr>
td>大于運(yùn)算符\${3 gt; 2}/td>
td>結(jié)果${3 > 2}/td>
/tr>
tr>
td>小于等于運(yùn)算符\${1 lt;= 2}/td>
td>結(jié)果${1 = 2}/td>
/tr>
tr>
td>大于等于運(yùn)算符\${3 gt;= 2}/td>
td>結(jié)果${3 >= 2}/td>
/tr>
/table>
table border=1>
tr>
td>邏輯運(yùn)算符/td>
td>結(jié)果/td>
/tr>
tr>
td colspan="2">邏輯運(yùn)算符/td>
/tr>
tr>
td>\${true true}/td>
td>結(jié)果${true true}/td>
/tr>
tr>
td>\${true false}/td>
td>結(jié)果${true false}/td>
/tr>
tr>
td>\${false false}/td>
td>結(jié)果${false false}/td>
/tr>
tr>
td colspan="2">邏輯運(yùn)算符||/td>
/tr>
tr>
td>\${true || true}/td>
td>結(jié)果${true || true}/td>
/tr>tr>
td>\${true || false}/td>
td>結(jié)果${true || false}/td>
/tr>tr>
td>\${false || false}/td>
td>結(jié)果${false || false}/td>
/tr>
tr>
td colspan="2">邏輯運(yùn)算符!/td>
/tr>
tr>
td>\${!true}/td>
td>結(jié)果${!true}/td>
/tr>tr>
td>\${!false}/td>
td>結(jié)果${!false}/td>
/tr>
/table>
table border=1>
tr>
td>條件運(yùn)算符/td>
td>結(jié)果/td>
/tr>
tr>
td>\${2>1?"Yes":"No"}/td>
td>結(jié)果${2>1?"Yes":"No"}/td>
/tr>
tr>
td>\${21?"Yes":"No"}/td>
td>結(jié)果${21?"Yes":"No"}/td>
/tr>
/table>
table border=1>
tr>
td>驗(yàn)證運(yùn)算符/td>
td>結(jié)果/td>
/tr>
tr>
td>\${empty param.username}/td>
td>結(jié)果${empty param.username}/td>
/tr>
tr>
td>\${empty param.password}/td>
td>結(jié)果${empty param.password}/td>
/tr>
/table>
table border=1>
tr>
td>括號運(yùn)算符及運(yùn)算符的優(yōu)先級/td>
td>結(jié)果/td>
/tr>
/table>
/body>
/html>
EL處理內(nèi)置對象:
“.”和"[]"符號是用來存取數(shù)據(jù)的
${applicationScope.user.username}
${applicationScope.user[0].username}
${applicationScope.user["user-name"]}
通過變量來傳值就必須使用[]
${applicationScope.user["data"]}
與存儲有關(guān)的內(nèi)置對象
!DOCTYPE html>
html>
head>
title>與存儲有關(guān)的內(nèi)置對象/title>
/head>
body>
%
//application范圍設(shè)置屬性name,值為application_name
application.setAttribute("name","application_name");
//session范圍設(shè)置屬性name,值為session_name
session.setAttribute("name","session_name");
//request范圍設(shè)置屬性name,值為request_name
request.setAttribute("name","request_name");
//page范圍設(shè)置屬性name,值為page_name
pageContext.setAttribute("name","page_name");
%>
%--獲取page范圍內(nèi)的name屬性--%>
page范圍內(nèi)的那么屬性的值為:${pageScope.name}br />
%--獲取request范圍內(nèi)的name的屬性--%>
request范圍內(nèi)的那么屬性的值為:${requestScope.name}br />
%--獲取session范圍內(nèi)的name的屬性--%>
session范圍內(nèi)的那么屬性的值為:${sessionScope.name}br />
%--獲取application范圍內(nèi)的name屬性--%>
application范圍內(nèi)的那么屬性的值為:${applicationScope.name}br />
/body>
/html>
與輸入有關(guān)的內(nèi)置對象
!DOCTYPE html>
html>
head>
title>用戶表單/title>
/head>
body>
form action="UserDemo.jsp" method="post">
用戶名:input type="text" name="username" />br />
密碼:input type="password" name="password" />br />
姓名:input type="text" name="name" />br />
性別:input type="radio" name="sex" value="男">男input type="radio" name="sex" value="女">女br />
愛好:br />
input type="checkbox" name="interest" value="打籃球">打籃球br />
input type="checkbox" name="interest" value="看書">看書br />
input type="checkbox" name="interest" value="旅行">旅行br />
input type="checkbox" name="interest" value="編程">編程br />
input type="submit" value="提交">
input type="reset" value="重置">
/form>
/body>
/html>
!DOCTYPE html>
html>
head>
title>接收用戶參數(shù)/title>
/head>
body>
%
//設(shè)置頁面編碼格式
request.setCharacterEncoding("gb2312");
%>
%--接收用戶參數(shù)--%>
用戶名:${span style="color:#003399;">param/span>.username}br />
密碼:${span style="color:#003399;">param/span>.password}br />
姓名:${span style="color:#003399;">param/span>.name}br />
性別:${span style="color:#003399;">param/span>.sex}br />
愛好:${span style="color:#003399;">paramValues/span>.interest[0]}
${span style="color:#003399;">paramValues/span>.interest[1]}
/body>
/html>
cookie內(nèi)置對象
!DOCTYPE html>
html>
head>
title>設(shè)置cookie的值/title>
/head>
body>
%
//設(shè)置cookie的值
Cookie c = new Cookie("username","root");
//添加cookie到客戶端
response.addCookie(c);
%>
a href="getCookieDemo.jsp">顯示cookie的值/a>
/body>
/html>
span style="color:#000000;">%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>取得cookie的值/title>
/head>
body>
cookie中的username的值為:${cookie.username.value}
/body>
/html>
header內(nèi)置對象
!DOCTYPE html>
html>
head>
title>取得header的值/title>
/head>
body>
${header["host"]}br />
${header["user-agent"]}br />
/body>
/html>
initParam內(nèi)置對象:獲取web站點(diǎn)中設(shè)置的環(huán)境變量
%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>獲得環(huán)境參數(shù)/title>
/head>
body>
username參數(shù)值:${initParam.username}br />
/body>
/html>
?xml version="1.0" encoding="ISO-8859-1"?>
web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
context-param>
param-name>username/param-name>
param-value>Zhangdapeng/param-value>
/context-param>
/web-app>
pageContex內(nèi)置對象
用來取得有關(guān)用戶請求和頁面的詳細(xì)信息
%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>pageContext演示/title>
/head>
body>
table border="1">
tr>
td>取得請求的參數(shù)的字符串/td>
td>${pageContext.request.queryString}/td>
/tr>tr>
td>取得請求URL/td>
td>${pageContext.request.requestURL}/td>
/tr>tr>
td>取得web應(yīng)用名稱/td>
td>${pageContext.request.contextPath}/td>
/tr>tr>
td>取得HTTP請求方式(POST/GET)/td>
td>${pageContext.request.method}/td>
/tr>tr>
td>取得使用的協(xié)議/td>
td>${pageContext.request.protocol}/td>
/tr>tr>
td>取得用戶IP地址/td>
td>${pageContext.request.remoteAddr}/td>
/tr>tr>
td>判斷session是否為新/td>
td>${pageContext.session.new}/td>
/tr>tr>
td>取得session的id/td>
td>${pageContext.session.id}/td>
/tr>
/table>
/body>
/html>
EL存取器:
使用存取器讀取JavaBean中的數(shù)據(jù)
package com.javaweb.ch08;
import java.util.*;
//一個簡單的JavaBean示例
public class Person{
//name屬性
private String name;
//age屬性
private int age;
//sex屬性
private String sex;
//friends屬性
private ArrayList friends;
//無參構(gòu)造方法
public Person(){
}
//自定義構(gòu)造的方法
public Person(String name,int age,String sex){
this.name = name;
this.age = age;
this.sex = sex;
}
//獲取name的屬性值
public String getName(){
return name;
}
//獲取age屬性值
public int getAge(){
return age;
}
//獲取sex的屬性值
public String getSex(){
return sex;
}
//設(shè)置name的屬性
public void setName(String name){
this.name = name;
}
//設(shè)置age的屬性值
public void setAge(int age){
this.age = age;
}
//設(shè)置sex的屬性值
public void setSex(String sex){
this.sex = sex;
}
//設(shè)置friends的值
public void setFriends(ArrayList friends){
this.friends = friends;
}
//獲取friends的屬性值
public ArrayList getFriends(){
return friends;
}
}
%@page language="java" contentType="text/html;charset=gb2312"%>
%@page import="java.util.*,com.javaweb.ch08.*" %>
!DOCTYPE html>
html>
head>
title>設(shè)置JavaBean中的屬性/title>
/head>
body>
%
//實(shí)例化一個Person
Person person = new Person("zhangdapeng",24,"男");
//創(chuàng)建一個friends實(shí)例
ArrayList friends = new ArrayList();
//添加值
friends.add("wang wu");
friends.add("li si");
person.setFriends(friends);
//存儲在session范圍內(nèi)
session.setAttribute("person",person);
%>
a href="GetJavaBean.jsp">跳轉(zhuǎn)到GetJavaBean.jsp/a>
/body>
/html>
%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>取得JavaBean中的屬性值/title>
/head>
body>
姓名:${sessionScope.person.name}br />
年齡:${sessionScope.person.age}br />
性別:${sessionScope.person.sex}br />
朋友:${sessionScope.person.friends[0]},${sessionScope.person.friends[1]}br />
/body>
/html>
使用存儲器讀取Map中的數(shù)據(jù)
%@page language="java" contentType="text/html;charset=gb2312"%>
%@page import="java.util.*,com.javaweb.ch08.*" %>
!DOCTYPE html>
html>
head>
title>設(shè)置Map頁面/title>
/head>
body>
%
//新建一個HashMap
HashMap userInfo = new HashMap();
//在HashMap中設(shè)置值
userInfo.put("username","zhangdapeng");
userInfo.put("password","zhnagda123");
//將值存儲到session范圍中
session.setAttribute("userInfo",userInfo);
%>
a href="GetMapDemo.jsp">跳轉(zhuǎn)到GetMapDemo.jsp/a>
/body>
/html>
%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>使用存儲器讀取map中的數(shù)據(jù)/title>
/head>
body>
用戶名:${sessionScope.userInfo.username}br />
密碼:${sessionScope.userInfo.password}br />
/body>
/html>
使用存儲器讀取數(shù)組中的數(shù)據(jù)
%@page language="java" contentType="text/html;charset=gb2312"%>
%@page import="java.util.*,com.javaweb.ch08.*" %>
!DOCTYPE html>
html>
head>
title>設(shè)置Array頁面/title>
/head>
body>
%
String[] names = {"zhangda1","zhangda2","zhangda3"};
//將值存儲到session范圍中
session.setAttribute("names",names);
%>
a href="GetMapDemo.jsp">跳轉(zhuǎn)到GetArrayDemo.jsp/a>
/body>
/html>
%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>使用存儲器讀取map中的數(shù)據(jù)/title>
/head>
body>
用戶名1:${sessionScope.names[0]}br />
用戶名2:${sessionScope.names[1]}br />
/body>
/html>
存儲器的復(fù)雜應(yīng)用
%@page language="java" contentType="text/html;charset=gb2312"%>
%@page import="java.util.*,com.javaweb.ch08.*" %>
!DOCTYPE html>
html>
head>
title>設(shè)置Array頁面/title>
/head>
body>
%
ArrayListPerson> persons = new ArrayListPerson>();
Person person1 = new Person("wang wu",24,"男");
Person person2 = new Person("wang liu",24,"女");
persons.add(person1);
persons.add(person2);
session.setAttribute("persons",persons);
%>
a href="GetMapDemo.jsp">跳轉(zhuǎn)到GetArrayDemo.jsp/a>
/body>
/html>
%@page language="java" contentType="text/html;charset=gb2312"%>
!DOCTYPE html>
html>
head>
title>使用存儲器讀取map中的數(shù)據(jù)/title>
/head>
body>
用戶名1:${sessionScope.persons[0].name},${sessionScope.persons[0].age},${sessionScope.persons[0].sex}br />
用戶名2:${sessionScope.persons[1].name},${sessionScope.persons[1].age},${sessionScope.persons[1].sex}br />
/body>
/html>
您可能感興趣的文章:- JSP頁面無法識別EL表達(dá)式問題解決方案
- 使用IDEA編寫jsp時EL表達(dá)式不起作用的問題及解決方法
- JSP中EL表達(dá)式用法_動力節(jié)點(diǎn)Java學(xué)院整理
- 淺談java里的EL表達(dá)式在JSP中不能解析的問題
- JAVA JSP頁面技術(shù)之EL表達(dá)式整理歸納總結(jié)
- 淺談jsp EL表達(dá)式取值過程、page和pagecontext的區(qū)別
- JSP中EL表達(dá)式的用法詳解(必看篇)
- jsp頁面中EL表達(dá)式被當(dāng)成字符串處理不顯示值問題的解決方法
- jsp中EL表達(dá)式獲取數(shù)據(jù)
- JSP 不能解析EL表達(dá)式的解決辦法
- JSP EL表達(dá)式詳細(xì)介紹
- jsp 不支持EL表達(dá)式,解決辦法
- jsp EL表達(dá)式詳解