1. <%@ page language="java"import="java.util.*" pageEncoding="GBK"%>
<html>
<head>
</head>
<body>
<%
request.setAttribute("info","www.MLDNJAVA.cn");
if(request.getAttribute("info")!=null){
%>
<h3><%=request.getAttribute("info") %></h3>
<%
}
%>
</body>
</html>
2. <%@ page language="java"import="java.util.*" pageEncoding="GBK"%>
<html>
<head>
</head>
<body>
<%
request.setAttribute("info", "welcome");
%>
<h3>${info}</h3>
</body>
</html>
3.表达式语言的内置对象
A:
<body>
<%
pageContext.setAttribute("info", "page");
request.setAttribute("info", "request");
session.setAttribute("info", "session");
application.setAttribute("info", "application");
%>
<h3>${info}</h3>
</body>
B:
<body>
<%
pageContext.setAttribute("info", "page");
request.setAttribute("info", "request");
session.setAttribute("info", "session");
application.setAttribute("info", "application");
%>
<h3>PAGE's infois:${pageScope.info}</h3>
<h3>REQUEST'infois:${requestScope.info}</h3>
<h3>SESSION'infois:${sessionScope.info}</h3>
<h3>APPLICATION'info is:${applicationScope.info}</h3>
</body>
4.调用内置对象操作:
<body>
<h3>IP地址:${pageContext.request.remoteAddr}</h3>
<h3>SESSION ID:${pageContext.session.id}</h3>
</body>
5.接受参数:
A:
<body>
<h3>通过内置对象接受输入参数:<%=request.getParameter("ref") %></h3>
<h3>通过表达式语言接收输入参数:${param.ref}</h3>
</body>
B:
Index.Jsp:
<body>
<form action="a.jsp"method="post">
兴趣:<input type="checkbox"name="inst"value="唱歌">唱歌
<input type="checkbox"name="inst"value="游泳">游泳
<input type="checkbox"name="inst"value="看书">看书
<input type="submit"value="显示">
</form>
</body>
a. jsp:
<body>
<%
request.setCharacterEncoding("GBK");
%>
<h3>第一个参数:${paramValues.inst[0]}</h3>
<h3>第二个参数:${paramValues.inst[1]}</h3>
<h3>第三个参数:${paramValues.inst[2]}</h3>
</body>
6.集合操作:
(1).list集合
<body>
<%
List all=new ArrayList();
all.add("zhang");
all.add("www,mldn.cn");
all.add("mldn@123.com");
request.setAttribute("allino",all);
%>
<h3>第一个元素:${allino[0]}</h3>
<h3>第二个元素:${allino[1]}</h3>
<h3>第三个元素:${allino[2]}</h3>
</body>
(2)Map集合
<body>
<%
Map map=new HashMap();
map.put("lxh", "lixinghua");
map.put("mldn", "www.mldn.cn");
map.put("email", "MLDN@qq.com");
request.setAttribute("info", map);
%>
<h3>第一个元素:${info["lxh"]}</h3>
<h3>第二个元素:${info["mldn"]}</h3>
<h3>第三个元素:${info["email"]}</h3>
</body>
7.运算符:
(1)大于,小于,等于操作;
<body>
<%
pageContext.setAttribute("num1", 20);
pageContext.setAttribute("num2", 30);
%>
<h3>星等判断:${num1==num2}</h3>
<h3>不等判断${num1!=num2}</h3>
<h3>大于判断${num1>num2}</h3>
<h3>小于判断${num1<num2}</h3>
<h3>小于等于判断${num1<=num2}</h3>
<h3>大于等于判断${num1>=num2}</h3>
</body>
(2).与,或,非操作
<body>
<%
pageContext.setAttribute("flagA", true);
pageContext.setAttribute("flagB", false);
%>
<h3>${flagA&&flagB}</h3>
<h3>${flagA||flagB}</h3>
<h3>${!flagA}</h3>
</body>
(3).验证运算符
<body>
<%
pageContext.setAttribute("num1", 10);
pageContext.setAttribute("num2",20);
pageContext.setAttribute("num3",30);
%>
<h3>${empty info}</h3>
<h3>${num1>num2?"大于":"小于"}</h3>
<h3>${num1*(num2+num3)}</h3>
</body>