EL内置对象

“.”和"[]"符号是用来存取数据的
${applicationScope.user.username}
${applicationScope.user[0].username}
${applicationScope.user["user-name"]}
通过变量来传值就必须使用[]
${applicationScope.user["data"]}
与存储有关的内置对象
01 <span style="color: rgb(0, 0, 0);"><%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>与存储有关的内置对象</title>
06 </head>
07 <body>
08 <%
09 //application范围设置属性name,值为application_name
10 application.setAttribute("name","application_name");
11 //session范围设置属性name,值为session_name
12 session.setAttribute("name","session_name");
13 //request范围设置属性name,值为request_name
14 request.setAttribute("name","request_name");
15 //page范围设置属性name,值为page_name
16 pageContext.setAttribute("name","page_name");
17 %>
18 <%--获取page范围内的name属性--%>
19 page范围内的那么属性的值为:${pageScope.name}<br />
20 <%--获取request范围内的name的属性--%>
21 request范围内的那么属性的值为:${requestScope.name}<br />
22 <%--获取session范围内的name的属性--%>
23 session范围内的那么属性的值为:${sessionScope.name}<br />
24 <%--获取application范围内的name属性--%>
25 application范围内的那么属性的值为:${applicationScope.name}<br />
26 </body>
27 </html></span>
与输入有关的内置对象

01 <span style="color: rgb(0, 0, 0);"><%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>用户表单</title>
06 </head>
07 <body>
08 <form action="UserDemo.jsp" method="post">
09 用户名:<input type="text" name="username" /><br />
10 密码:<input type="password" name="password" /><br />
11 姓名:<input type="text" name="name" /><br />
12 性别:<input type="radio" name="sex" value="男">男<input type="radio" name="sex" value="女">女<br />
13 爱好:<br />
14 <input type="checkbox" name="interest" value="打篮球">打篮球<br />
15 <input type="checkbox" name="interest" value="看书">看书<br />
16 <input type="checkbox" name="interest" value="旅行">旅行<br />
17 <input type="checkbox" name="interest" value="编程">编程<br />
18 <input type="submit" value="提交">
19 <input type="reset" value="重置">
20 </form>
21 </body>
22 </html></span>

01 <span style="color: rgb(0, 0, 0);"><%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>接收用户参数</title>
06 </head>
07 <body>
08 <%
09 //设置页面编码格式
10 request.setCharacterEncoding("gb2312");
11 %>
12 <%--接收用户参数--%>
13 用户名:${<span style="color: rgb(0, 51, 153);">param</span>.username}<br />
14 密码:${<span style="color: rgb(0, 51, 153);">param</span>.password}<br />
15 姓名:${<span style="color: rgb(0, 51, 153);">param</span>.name}<br />
16 性别:${<span style="color: rgb(0, 51, 153);">param</span>.sex}<br />
17 爱好:${<span style="color: rgb(0, 51, 153);">paramValues</span>.interest[0]}
18 ${<span style="color: rgb(0, 51, 153);">paramValues</span>.interest[1]}
19 </body>
20 </html></span>
cookie内置对象

01 <span style="color: rgb(0, 0, 0);"><%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>设置cookie的值</title>
06 </head>
07 <body>
08 <%
09 //设置cookie的值
10 Cookie c = new Cookie("username","root");
11 //添加cookie到客户端
12 response.addCookie(c);
13 %>
14 <a href="getCookieDemo.jsp">显示cookie的值</a>
15 </body>
16 </html></span>

01 <span style="color: rgb(0, 0, 0);"><%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>取得cookie的值</title>
06 </head>
07 <body>
08 cookie中的username的值为:${cookie.username.value}
09 </body>
10 </html></span>
header内置对象

01 <span style="color: rgb(0, 0, 0);"><%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>取得header的值</title>
06 </head>
07 <body>
08 ${header["host"]}<br />
09 ${header["user-agent"]}<br />
10 </body>
11 </html></span>

initParam内置对象:获取web站点中设置的环境变量

01 <%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>获得环境参数</title>
06 </head>
07 <body>
08 username参数值:${initParam.username}<br />
09 </body>
10 </html>

01 <?xml version="1.0" encoding="ISO-8859-1"?>
02 <web-app xmlns="http://java.sun.com/xml/ns/javaee"
03 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
04 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
05 version="2.5">
06 <context-param>
07 <param-name>username</param-name>
08 <param-value>Zhangdapeng</param-value>
09 </context-param>
10 </web-app>
pageContex内置对象
用来取得有关用户请求和页面的详细信息

01 <%@page language="java" contentType="text/html;charset=gb2312"%>
02 <!DOCTYPE html>
03 <html>
04 <head>
05 <title>pageContext演示</title>
06 </head>
07 <body>
08 <table border="1">
09 <tr>
10 <td>取得请求的参数的字符串</td>
11 <td>${pageContext.request.queryString}</td>
12 </tr><tr>
13 <td>取得请求URL</td>
14 <td>${pageContext.request.requestURL}</td>
15 </tr><tr>
16 <td>取得web应用名称</td>
17 <td>${pageContext.request.contextPath}</td>
18 </tr><tr>
19 <td>取得HTTP请求方式(POST/GET)</td>
20 <td>${pageContext.request.method}</td>
21 </tr><tr>
22 <td>取得使用的协议</td>
23 <td>${pageContext.request.protocol}</td>
24 </tr><tr>
25 <td>取得用户IP地址</td>
26 <td>${pageContext.request.remoteAddr}</td>
27 </tr><tr>
28 <td>判断session是否为新</td>
29 <td>${pageContext.session.new}</td>
30 </tr><tr>
31 <td>取得session的id</td>
32 <td>${pageContext.session.id}</td>
33 </tr>
34 </table>
35 </body>
36 </html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值