想飞的程序员

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

1.1 EL作用

                   jsp的核心语法: jsp表达式 <%=%>和 jsp脚本<%  %>。

                   以后开发jsp的原则: 尽量在jsp页面中少写甚至不写java代码。

 

                  使用EL表达式替换掉jsp表达式

 

                   EL表达式作用: 向浏览器输出域对象中的变量值或表达式计算的结果!!!

 

                   语法: ${变量或表达式}

1.2 EL语法

           

1               <%
2               String name = "rose";  
3               //放入域中
4               //pageContext.setAttribute("name",name);
5                pageContext.setAttribute("name",name,PageContext.REQUEST_SCOPE); 
6                %>
7                <%=name %>//使用jsp表达式显示
8 
9              ${name} //使用EL表达式显示

 

            1)输出基本数据类型变量

                                          1.1 从四个域获取

                                                ${name}                ${name } 等价于<%=pageContext.findAttribute("name")%>

                                          1.2 指定域获取

                                                 ${pageScope.name}       ${pageScope.name } 等价于 <%= pageContext.getAttribute("name",PageContext.PAGE_SCOPE)%>

                    域范围: pageScoep / requestScope / sessionScope / applicationScope

            

                                   2)输出对象的属性值

1 <%
2          //保存数据
3          Student student = new Student("eric",20);
4          //放入域中
5          pageContext.setAttribute("student",student);
6 %>

              <%--使用EL获取对象 --%>
              ${student.name} - ${student.age }
              <%--
                 ${student.name} 等价于     (相当于调用getXX()方法)<%=((Student)pageContext.findAttribute("student")).getName()%>
                 --%>

          

            3)输出集合对象

                                       List  和 Map 原理同2)

            4)EL表达式计算

          

                            

          重点:      判断null: ${name==null }<br/>
               判断空字符: ${name=="" }<br/>
               判空:  ${name==null || name=="" }
               另一种判空写法: ${empty name }

posted on 2015-11-03 14:32  想飞的程序员  阅读(159)  评论(0编辑  收藏  举报