配色: 字号:
jsp中jstl标签库core全解析
2016-12-23 | 阅:  转:  |  分享 
  
jsp中jstl标签库core全解析



一::



查看c.tld可知:







Like<%=...>,butforexpressions.



out

org.apache.taglibs.standard.tag.rt.core.OutTag

JSP





Expressiontobeevaluated.



value

true

true







Defaultvalueiftheresultingvalueisnull.



default

false

true







Determineswhethercharacters<,>,&,'',"inthe

resultingstringshouldbeconvertedtotheir

correspondingcharacterentitycodes.Defaultvalueis

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会解析颜色





二:







Setstheresultofanexpressionevaluationina''scope''



set

org.apache.taglibs.standard.tag.rt.core.SetTag

JSP





Nameoftheexportedscopedvariabletoholdthevalue

specifiedintheaction.Thetypeofthescopedvariableis

whatevertypethevalueexpressionevaluatesto.



var

false

false







Expressiontobeevaluated.



value

false

true



java.lang.Object









Targetobjectwhosepropertywillbeset.Mustevaluateto

aJavaBeansobjectwithsetterpropertyproperty,ortoa

java.util.Mapobject.



target

false

true







Nameofthepropertytobesetinthetargetobject.



property

false

true







Scopeforvar.



scope

false

false





设置属性:相当于setAttribute();





属性搭配一:var:存储容器中的属性变量名



value:属性值



属性搭配二:target:容器中的一个对象



property:对象属性名



value:属性值



scope:容器的种类(四种,二种搭配可选可不选)



代码示例:











${aa},${requestScope.aa}









三:







Removesascopedvariable(fromaparticularscope,ifspecified).



remove

org.apache.taglibs.standard.tag.common.core.RemoveTag

empty





Nameofthescopedvariabletoberemoved.



var

true

false







Scopeforvar.



scope

false

false





在容器中移除var值属性,默认全部容器





属性:var:容器中的属性值



scope:指定的容器



代码示例:









${aa}

四:









Simpleconditionaltag,whichevalutesitsbodyifthe

suppliedconditionistrueandoptionallyexposesaBoolean

scriptingvariablerepresentingtheevaluationofthiscondition



if

org.apache.taglibs.standard.tag.rt.core.IfTag

JSP





Thetestconditionthatdetermineswhetheror

notthebodycontentshouldbeprocessed.



test

true

true

boolean







Nameoftheexportedscopedvariableforthe

resultingvalueofthetestcondition.Thetype

ofthescopedvariableisBoolean.



var

false

false







Scopeforvar.



scope

false

false





判断test属性值真假,是否执行里面的代码





属性:test:一个返回boolean值得表达式



var:存储test返回值的变量名



scope:存储var变量的容器



代码示例:







10}"var="boo">

dfdfdfdf





NOooooo





五:









Simpleconditionaltagthatestablishesacontextfor

mutuallyexclusiveconditionaloperations,markedby

and



choose

org.apache.taglibs.standard.tag.common.core.ChooseTag

JSP









Subtagofthatincludesitsbodyifits

conditionevalutesto''true''



when

org.apache.taglibs.standard.tag.rt.core.WhenTag

JSP





Thetestconditionthatdetermineswhetherornotthe

bodycontentshouldbeprocessed.



test

true

true

boolean











Subtagofthatfollowstags

andrunsonlyifallofthepriorconditionsevaluatedto

''false''



otherwise

org.apache.taglibs.standard.tag.common.core.OtherwiseTag

JSP



一种类似于swich-case结构





:无属性,标记开始



:相当于case可重复属性test:会返回为boolea值得表达式



:无属性,相当于defaule语句



代码示例:









=90}">

优秀



=80}">

良好



=70}">

中等





不行





六:普通循环:

增强for循环:









Thebasiciterationtag,acceptingmanydifferent

collectiontypesandsupportingsubsettingandother

functionality



forEach

org.apache.taglibs.standard.tag.rt.core.ForEachTag

org.apache.taglibs.standard.tei.ForEachTEI

JSP





Collectionofitemstoiterateover.



items

false

true

java.lang.Object



java.lang.Object









Ifitemsspecified:

Iterationbeginsattheitemlocatedatthe

specifiedindex.Firstitemofthecollectionhas

index0.

Ifitemsnotspecified:

Iterationbeginswithindexsetatthevalue

specified.



begin

false

true

int







Ifitemsspecified:

Iterationendsattheitemlocatedatthe

specifiedindex(inclusive).

Ifitemsnotspecified:

Iterationendswhenindexreachesthevalue

specified.



end

false

true

int







Iterationwillonlyprocesseverystepitemsof

thecollection,startingwiththefirstone.



step

false

true

int







Nameoftheexportedscopedvariableforthe

currentitemoftheiteration.Thisscoped

variablehasnestedvisibility.Itstypedepends

ontheobjectoftheunderlyingcollection.



var

false

false







Nameoftheexportedscopedvariableforthe

statusoftheiteration.Objectexportedisoftype

javax.servlet.jsp.jstl.core.LoopTagStatus.Thisscopedvariablehasnested

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:记录当前遍历数



代码示例:







<%

Listlist2=newArrayList();

list2.add("aa1111");

list2.add("bb2222");

list2.add(200);

list2.add(100);

request.setAttribute("lis2",list2);

%>



${aa},





<%

Mapmap=newHashMap();

map.put("name","Rose");

map.put("age",55);

map.put("tel","13566668888");

pageContext.setAttribute("m",map);

%>







${im.key}=${im.value}







<%

Stringstrs[]={"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长度分割









Iteratesovertokens,separatedbythesupplieddelimeters



forTokens

org.apache.taglibs.standard.tag.rt.core.ForTokensTag

JSP





Stringoftokenstoiterateover.



items

true

true

java.lang.String



java.lang.String









Thesetofdelimiters(thecharactersthat

separatethetokensinthestring).



delims

true

true

java.lang.String







Iterationbeginsatthetokenlocatedatthe

specifiedindex.Firsttokenhasindex0.



begin

false

true

int







Iterationendsatthetokenlocatedatthe

specifiedindex(inclusive).



end

false

true

int







Iterationwillonlyprocesseverysteptokens

ofthestring,startingwiththefirstone.



step

false

true

int







Nameoftheexportedscopedvariableforthe

currentitemoftheiteration.Thisscoped

variablehasnestedvisibility.



var

false

false







Nameoftheexportedscopedvariableforthe

statusoftheiteration.Objectexportedisof

type

javax.servlet.jsp.jstl.core.LoopTag

Status.Thisscopedvariablehasnested

visibility.



varStatus

false

false





型:





属性:items:要分割的表达式



delims:分隔符



var:分割的每一项



代码示例:







${str}



八:相当于动态导入







RetrievesanabsoluteorrelativeURLandexposesitscontents

toeitherthepage,aStringin''var'',oraReaderin''varReader''.



import

org.apache.taglibs.standard.tag.rt.core.ImportTag

org.apache.taglibs.standard.tei.ImportTEI

JSP





TheURLoftheresourcetoimport.



url

true

true







Nameoftheexportedscopedvariableforthe

resource''scontent.Thetypeofthescoped

variableisString.



var

false

false







Scopeforvar.



scope

false

false







Nameoftheexportedscopedvariableforthe

resource''scontent.Thetypeofthescoped

variableisReader.



varReader

false

false







Nameofthecontextwhenaccessingarelative

URLresourcethatbelongstoaforeign

context.



context

false

true







Characterencodingofthecontentattheinput

resource.



charEncoding

false

true





属性:url:导入的资源路径(可访问)





代码示例:







九:链接,具有重写url技术









CreatesaURLwithoptionalqueryparameters.



url

org.apache.taglibs.standard.tag.rt.core.UrlTag

JSP





Nameoftheexportedscopedvariableforthe

processedurl.Thetypeofthescopedvariableis

String.



var

false

false







Scopeforvar.



scope

false

false







URLtobeprocessed.



value

false

true







NameofthecontextwhenspecifyingarelativeURL

resourcethatbelongstoaforeigncontext.



context

false

true





属性:value:资源路径(可访问)





代码示例



?

1

I18N演示

十:重定向







RedirectstoanewURL.



redirect

org.apache.taglibs.standard.tag.rt.core.RedirectTag

JSP





TheURLoftheresourcetoredirectto.



url

false

true







NameofthecontextwhenredirectingtoarelativeURL

resourcethatbelongstoaforeigncontext.



context

false

true





属性:url:资源路径(可访问)

代码示例





<%--



--%>

献花(0)
+1
(本文系thedust79首藏)