一、JavaBean:任何一个类都称为JavaBean,一般泛指实体类(实体类还有一种叫法:domain)
<jsp:userBean>
id:对象名
class:类的权限定名
scope:作用域
<jsp:setProperty>
Property:实体类的属性
Value:属性值
Name:对象名
提示:peoperty的值可以为“*”;代表:可以将请求参数的值设置为该对象的属性值
<jsp: getProperty >
Property:属性名
Name:对象名
JavaBean在JSP中使用的示例:
<!-- javaBean的用法 -->
<!-- id变量名 class类的权限定名 -->
<!--设值> <jsp:useBean id="buser" class="com.sun.entity.Buser"></jsp:useBean> <jsp:setProperty property="ubid" name="buser" value="1"/> <jsp:setProperty property="uname" name="buser" value="sa"/> <jsp:setProperty property="upass" name="buser" value="123"/>
<!-- id变量名 class类的权限定名 -->
<jsp:getProperty property="ubid" name="buser"/><jsp:getProperty property="uname" name="buser"/><jsp:getProperty property="upass" name="buser"/><!-- 可通过此方式设置所有属性值(可通过传参传值) --><jsp:setProperty property="*" name="buser"/><!--拿值-->
二EL表达式
1. 什么是EL
EL:(Expressionlanguage)表达式语言
2. EL功能
功能:替换JSP页面中的复杂代码
1. EL语法
1.${ ELexpression}
2.${bean.name}或${bean[“name”]}→本质调用了bean的getName()方法
注意:如果域对象中属性名带有特殊字符,使用[ ]会比较方便
2. EL中的隐含对象
PageScope
RequestScope
SessionScope
Application
示例:
根据不同情况可省略<!-- 设值 --> <% pageContext.setAttribute("pageContext", "1"); request.setAttribute("request", "2"); session.setAttribute("session", "3"); application.setAttribute("application", "4"); %> <!-- 拿值(1)--> pageContext:<%=pageContext.getAttribute("pageContext")%><br/> request:<%=request.getAttribute("request")%><br/> session:<%=session.getAttribute("session")%><br/> application:<%=application.getAttribute("application")%><br/> <hr/> <!--拿值(2) --> pageContext:${pageScope.pageContext }<br/> request:${request }<br/> session:${session }<br/> application:${application }<br/>
3. 参数有关的隐含对象
Param
<form action="two.jsp" method="post"><input type="text" name="uname"><br/><input type="password" name="upass"><br/><input type="submit" value="登录"> </form><!-- 拿(2) -->${param.uname}<br/>${param.upass}<!--设值-->
ParamValues
当有多个值的时候
${paramValues.hobby[0]}
4. EL运算符
算数运算符
${3/1} 其余类似
关系运算符
${3>2}
Empty运算符
${Empty 集合}判断集合中的值,是否为空,结果为true或false
<% List<Buser> b=new ArrayList(); b.add(new Buser("a","a")); session.setAttribute("b",b); %> 集合中是否为空:${empty sessionScope.b}