jsp中jstl标签库core全解析
首先来认识一下jstl:
下面来介绍一下核心标签库:
前言:jstl是用来辅助el表达式,用来在页面显示复杂结构的数据
一:
查看c.tld可知:
like <%= ... >, but for expressions. out org.apache.taglibs.standard.tag.rt.core.outtag jsp expression to be evaluated. value true true default value if the resulting value is null. default false true determines whether characters <,>,&,'," in the resulting string should be converted to their corresponding character entity codes. default value is true. escapexml false true
向界面输出value值(可输出特殊字符):
属性解析: value: 输出的值(el表达式,字符串)
escapexml:是否将特殊字符转化,默认true
default: value值为null时输出
代码示例:
<% pagecontext.setattribute("name", "tom"); pagecontext.setattribute("name2", "tom"); %> ${name2}out会将<>解析成&qt;>,这样保证界面原样输出,而一般的el表达式不转化<>,hyml会解析颜色
二:
sets the result of an expression evaluation in a 'scope' set org.apache.taglibs.standard.tag.rt.core.settag jsp name of the exported scoped variable to hold the value specified in the action. the type of the scoped variable is whatever type the value expression evaluates to. var false false expression to be evaluated. value false true java.lang.object target object whose property will be set. must evaluate to a javabeans object with setter property property, or to a java.util.map object. target false true name of the property to be set in the target object. property false true scope for var. scope false false设置属性:相当于setattribute();
属性搭配一: var:存储容器中的属性变量名
value:属性值
属性搭配二:target:容器中的一个对象
property:对象属性名
value:属性值
scope:容器的种类(四种,二种搭配可选可不选)
代码示例:
${aa}, ${requestscope.aa}
三:
removes a scoped variable (from a particular scope, if specified). remove org.apache.taglibs.standard.tag.common.core.removetag empty name of the scoped variable to be removed. var true false scope for var. scope false false在容器中移除var值属性,默认全部容器
属性: var:容器中的属性值
scope:指定的容器
代码示例:
${aa}四:
simple conditional tag, which evalutes its body if the supplied condition is true and optionally exposes a boolean scripting variable representing the evaluation of this condition if org.apache.taglibs.standard.tag.rt.core.iftag jsp the test condition that determines whether or not the body content should be processed. test true true boolean name of the exported scoped variable for the resulting value of the test condition. the type of the scoped variable is boolean. var false false scope for var. scope false false判断test属性值真假,是否执行里面的代码
属性: test:一个返回boolean值得表达式
var:存储test返回值的变量名
scope: 存储var变量的容器
代码示例:
dfdfdfdf noooooo五:
simple conditional tag that establishes a context for mutually exclusive conditional operations, marked by and choose org.apache.taglibs.standard.tag.common.core.choosetag jsp
subtag of that includes its body if its condition evalutes to 'true' when org.apache.taglibs.standard.tag.rt.core.whentag jsp the test condition that determines whether or not the body content should be processed. test true true boolean
subtag of that follows tags and runs only if all of the prior conditions evaluated to 'false' otherwise org.apache.taglibs.standard.tag.common.core.otherwisetag jsp一种类似于swich-case结构
代码示例:
优秀 良好 中等 不行六:普通循环:
增强for循环:
the basic iteration tag, accepting many different collection types and supporting subsetting and other functionality foreach org.apache.taglibs.standard.tag.rt.core.foreachtag org.apache.taglibs.standard.tei.foreachtei jsp collection of items to iterate over. items false true java.lang.object java.lang.object if items specified: iteration begins at the item located at the specified index. first item of the collection has index 0. if items not specified: iteration begins with index set at the value specified. begin false true int if items specified: iteration ends at the item located at the specified index (inclusive). if items not specified: iteration ends when index reaches the value specified. end false true int iteration will only process every step items of the collection, starting with the first one. step false true int name of the exported scoped variable for the current item of the iteration. this scoped variable has nested visibility. its type depends on the object of the underlying collection. var false false name of the exported scoped variable for the status of the iteration. object exported is of type javax.servlet.jsp.jstl.core.looptagstatus. this scoped variable has nested visibility. varstatus false false第一套普通循环相当于:for( var=begin; var<=end; var+=step)
属性:begin:起始值
end:结尾值
step:步长值
var:表示目前的循环值
第二套属性搭配相当于:for( var : items )
属性:items:集合/数组的引用名
var:每一项的变量名
varstatus=""该属性可加可不加:有俩个下级变量:
index:记录当前下标值 items-var型从0开始 begin-end-step型从begin开始
count:记录当前遍历数
代码示例:
<% list list2 = new arraylist(); list2.add("aa1111" ); list2.add("bb2222"); list2.add(200); list2.add(100); request.setattribute("lis2", list2); %> ${aa } , <% map map = new hashmap(); map.put("name", "rose"); map.put("age",55); map.put("tel", "13566668888"); pagecontext.setattribute("m", map); %> ${im.key} = ${im.value } <% string strs[] ={"aaa","bbb","111","2222"}; pagecontext.setattribute("strs", strs); %> ${str} ,, 看看foreach标签中的varstatus属性---idx.index是元素的下标(从0开始),idx.count是元素的序号(从1开始计数) ${str} ---- index= ${idx.index} count= ${idx.count} ${i} --${idx.count}七:分隔符拆分
从begin-end间,以step长度分割
iterates over tokens, separated by the supplied delimeters fortokens org.apache.taglibs.standard.tag.rt.core.fortokenstag jsp string of tokens to iterate over. items true true java.lang.string java.lang.string the set of delimiters (the characters that separate the tokens in the string). delims true true java.lang.string iteration begins at the token located at the specified index. first token has index 0. begin false true int iteration ends at the token located at the specified index (inclusive). end false true int iteration will only process every step tokens of the string, starting with the first one. step false true int name of the exported scoped variable for the current item of the iteration. this scoped variable has nested visibility. var false false name of the exported scoped variable for the status of the iteration. object exported is of type javax.servlet.jsp.jstl.core.looptag status. this scoped variable has nested visibility. varstatus false false
属性:items:要分割的表达式
delims:分隔符
var:分割的每一项
代码示例:
${str}八:
retrieves an absolute or relative url and exposes its contents to either the page, a string in 'var', or a reader in 'varreader'. import org.apache.taglibs.standard.tag.rt.core.importtag org.apache.taglibs.standard.tei.importtei jsp the url of the resource to import. url true true name of the exported scoped variable for the resource's content. the type of the scoped variable is string. var false false scope for var. scope false false name of the exported scoped variable for the resource's content. the type of the scoped variable is reader. varreader false false name of the context when accessing a relative url resource that belongs to a foreign context. context false true character encoding of the content at the input resource. charencoding false true属性:url:导入的资源路径(可访问)
代码示例:
九:
creates a url with optional query parameters. url org.apache.taglibs.standard.tag.rt.core.urltag jsp name of the exported scoped variable for the processed url. the type of the scoped variable is string. var false false scope for var. scope false false url to be processed. value false true name of the context when specifying a relative url resource that belongs to a foreign context. context false true属性:value:资源路径(可访问)
代码示例
i18n演示十:
redirects to a new url. redirect org.apache.taglibs.standard.tag.rt.core.redirecttag jsp the url of the resource to redirect to. url false true name of the context when redirecting to a relative url resource that belongs to a foreign context. context false true属性:url:资源路径(可访问)
代码示例
<%-- --%>
上一篇: C++数据的抽象与封装:类与对象(1)
下一篇: Asp.net mvc 数据访问层