首页 技术 正文
技术 2022年11月18日
0 收藏 910 点赞 4,306 浏览 2527 个字

1.从特定域中获取值;

2.从请求页面的input标签中,获取值;(同servlet中的getParameter和getParameterValues);

3.获取请求头(同servlet中的getHeader和getHeaders);

4.获取cookie和session;

5.获取全局参数;

前驱页面:

<%@ 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="/JSP_Study/el_expression/04el.jsp">
name:<input name="name" type="text" value="aaa"/><br>
name:<input name="name" type="text" value="bbb"/><br>
<input type="submit" value="跳入04el.jsp"/></form>
</body>
</html>

测试El的JSP:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false" import="java.util.*, java.lang.*"%>
<%
// 为什么我这儿加一个逻辑判断仍然不对?
boolean t = (request.getParameter("name") == null);
System.out.println(t);
if(request.getParameter("name") == null) {
/* request.getRequestDispatcher("04pre_04el.jsp").forward(request, response); */
/* response.sendRedirect("/el_expression/04pre_04el.jsp"); */
response.sendRedirect("/JSP_Study/el_expression/04pre_04el.jsp"); // 重定向是浏览器行为!!!
} else { // 此处必须写else :并发执行不然会出现空指针异常!!!
// 去理解jsp的生成过程,转化成.class文件的过程,是否是因为存在并发的执行操作。
%> <!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>EL的11个内置对象</title>
</head>
<body><%--
1) 1.pageContext 等价于 jsp中的pageContext内置对象
--%>
<%-- 获取上下文路径:此处的两种方式都可以,我熟悉的是通过servletContext来获取上下文路径;这里提供的request获得不太明白 --%>
${pageContext.servletContext.contextPath }<br>
${pageContext.request.contextPath }<br>
<hr> <%--
2.pageScope
3.requestScope
4.sessionScope
5.applicationScope
从指定的域中获取数据
--%> <%--
2) 6.param:获取参数
7.paramValues:获取所有参数值
--%>
用JSP内置的request的getParameter获取的:<%=request.getParameter("name") %><br>
用EL的param获取的:${param['name'] }<br>
用JSP内置的request的getParameterValues获取的:<%=request.getParameterValues("name")[1] %><br>
用EL的paramValues获取的:${paramValues['name'][0] } -- ${paramValues['name'][1] }
<hr>
<%--
3) 8.header:获取请求头
9.headerValues
类似上面的param和paramValues
--%>
JSP内置对象header获取:<%=request.getHeader("host") %><br>
JSP内置对象headers获取:<%=request.getHeaders("host").nextElement() %><br>
EL内置对象header获取:${header['host'] }<br>
EL内置对象headerValues获取:${headerValues['host'][0] }
<hr> <%--
4)10.cookie: 获取cookie
--%>
<hr/>
<%=request.getCookies()[0].getValue() %><br/>
${cookie['JSESSIONID'].name } - ${cookie['JSESSIONID'].value }
<hr/> <%--
5)11.initParam: 获取全局参数
--%>
<%=application.getInitParameter("AAA") %><br/>
${initParam['AAA'] }
</body>
</html>
<%} %>
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,075
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,551
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,399
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,811
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,892