JSTL标签库概述

          *作用:和EL表达式一起取代<% %>

                   *版本:1.0             1.1和1.2(区别不大)

                            *1.0EL表达式没有纳入规范

                            *1.1和1.2EL表达式纳入规范

                           

             * 下载jar包,导入到工程中

                            jstl.jar

                            standard.jar

                           

                   *标签库

                            c.tld          核心的标签库

                            fn.tld                  EL表达式标签库

                           

         *JSTL的快速入门

                   *导入相应jar包。

                   *新建JSP的文件,引入标签库

                            <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  

                   *直接使用标签库

                           

                           

         *JSTL的标签

                                 输出内容

                            value         :输出的内容(常量或者变量)

                            default     :默认值

                            escapeXml:默认是true,进行转义,设置成false,不转义。

                           

                            代码:

                                    

                                    

                                    

                                    

                                     超链接" escapeXml="false"/>

                                    

                  

                            *属性

                                     var :定义属性

                                     value         :存入的值

                                     scope        :域范围

                                    

                                     target       :修改JavaBean对象

                                     property:修改的属性

                                    

                            *向4个web域对象存入值

                                    

                                    

                            *修改JavaBean对象属性的值  

                                    

                                    

                  

                            *属性

                                     var             :删除的属性

                                     scope        :在域的范围

                                    

                            *代码

                                    

                                     ${name }

 

                                    

                                     ${name}

                                    

                   *

                            *属性:var   把异常的信息保存变量中

                            *代码

                                    

                                               <%

                                                        inta = 10/0;

                                               %>

                                    

                                     ${e.message }

                                    

                   *     没有标签

                            *属性

                                     *test        判断的条件

                                     *var         计算的结果保存到变量中

                                     *scope    域的范围

                                    

                            *代码

                                    

                                    

                                               i>= 10

                                    

                                    

                                               i< 10

                                    

                                     ${x }

                                    

                   *标签

                           

                           

                           

                            代码:

                                    

                                    

                                              

                                                        i>= 10

                                              

                                              

                                                        i< 10

                                              

                                              

                                                        其他

                                              

                                    

                                    

                                    

                   *(*****)

                            *循环遍历数据(数组,集合,Map集合)

                            *属性

                                     var :遍历数据的类型

                                     items        :要遍历的内容

                                    

                                     begin        :从哪开始

                                     end            :到哪结束

                                     step :步长

                                    

                                     varStatus:记录循环遍历的信息

                                               *index

                                               *count(常用)

                                               *first

                                               *last

                                              

                            *代码

                                     <%

                                               String[] arrs = {"美美","小凤","芙蓉","小苍"};

                                               request.setAttribute("arrs",arrs);

                                     %>

                                    

                                    

                                               ${s }

                                    

 

                                    

遍历集合

                                     <%

                                               Listlist = new ArrayList();

                                               list.add("美美");

                                               list.add("小凤");

                                               list.add("芙蓉");

                                               list.add("小泽");

                                               request.setAttribute("list",list);

                                     %>

                                    

                                               ${s }

                                    

 

                                    

遍历Map集合

                                     <%

                                               Mapmap = new HashMap();

                                               map.put("aa","美美");

                                               map.put("bb","小凤");

                                               map.put("cc","芙蓉");

                                               request.setAttribute("map",map);

                                     %>

                                    

                                               ${entry.key } -- ${ entry.value }

                                    

                                    

                                    

遍历对象的集合

                                     <%

                                               ListuList = new ArrayList();

                                               uList.add(newUser("美美","123"));

                                               uList.add(newUser("小风","234"));

                                               uList.add(newUser("芙蓉","345"));

                                               request.setAttribute("uList",uList);

                                     %>

                                    

                                               ${user.username } -- ${ user.password }

                                    

                                    

                                    

                                    

迭代数据

                                    

迭代从1到10

                                    

                                               ${i }

                                    

 

 

                                    

计算从1加到100的和

                                    

                                    

                                              

                                    

                                     ${sum }

                                    

                                    

遍历10到100的偶数,每到第3个数,显示红色

                                    

                                              

                                                       

                                                                 ${ i }

                                                       

                                                       

                                                                 ${ i }

                                                       

                                                       

                                                                 ${i }

                                                       

                                              

                                    

                                    

                  

                   *    传递参数

                            *属性

                                     name        :参数名称    

                                     value         :参数的值

                                    

                   *    包含页面

                            *url          :引入页面的地址

                            *context :虚拟路径

                            *var                   :引入页面保存到属性中

                            *scope              :域的范围

                           

                            *代码

                                    

                                              

                                    

                                     ${i }

                                    

                   *

                            标签用于在JSP页面中构造一个URL地址,其主要目的是实现URL重写。

                            URL重写就是将会话标识号以参数形式附加在URL地址后面

                            http://localhost/day12/demo?jsessionid=xxxxxxxxxxxxxxxxxx;

                           

                            *属性

                                     *var                   :声明属性

                                     *value               :地址

                                     *scope              :域范围

                                     *context :虚拟路径

                                    

                            *代码

                                    

                                              

                                    

 

                                     choose

                                    

                   *重定向

                            *属性

                                     *url          :重定向的地址

                                     *context :虚拟路径

                            *代码

                                    

                                              

                                    

                  

                   *分隔字符串(了解)

                           

分隔字符串

                           

                           

                                     ${x }

                           

你可能感兴趣的:(JavaEE)