【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx

上传人:聆听****声音 文档编号:852359 上传时间:2023-04-29 格式:DOCX 页数:35 大小:1.08MB
下载 相关 举报
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第1页
第1页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第2页
第2页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第3页
第3页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第4页
第4页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第5页
第5页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第6页
第6页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第7页
第7页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第8页
第8页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第9页
第9页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第10页
第10页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第11页
第11页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第12页
第12页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第13页
第13页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第14页
第14页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第15页
第15页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第16页
第16页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第17页
第17页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第18页
第18页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第19页
第19页 / 共35页
【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx_第20页
第20页 / 共35页
亲,该文档总共35页,到这儿已超出免费预览范围,如果喜欢就下载吧!
下载资源
资源描述

【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx

《【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx》由会员分享,可在线阅读,更多相关《【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx(35页珍藏版)》请在冰点文库上搜索。

【精品文档】532关于计算机专业JSP表达式语言介绍简介概述的毕业设计论文英文英语外文文献翻译成品资料:JSP和EL介绍中英文双语对照15文档格式.docx

Unliketheearlierchapters,thischapterprovidesamorein-depthexplorationofacornerstoneelementoftheJSPstandard:

JSP’sExpressionLanguage,orELforshort.

Inthischapter,youwilldiscoverthefollowing:

❑WhyELisanindispensablepartofJSP2.0

❑HowtouseELnamedvariables

❑HowtoperformtypeconversionandcoercioninEL

❑HowtohandlenullvaluesinEL

❑Howtoworkwitharithmetic,logical,comparison,andotheroperatorsinEL

❑ThedifferentwaysofaccessingmembersofacollectioninEL

❑HowtoaccesspropertiesofobjectsinEL

❑HowtoaccessnestedobjectpropertiesinEL

❑HowtouseimplicitobjectsinEL

❑HowtodefineandaccessfunctionsinEL

❑HowtouseanamespacewhenreferencingELfunctions

Thischaptercoversalotofground,andincludesfiveseparateexamples.Bytheendofthechapter,youshouldbeveryfamiliarwithEL,andbecomfortableusingitinyourownapplications.

ELandItsVitalRoleinJSP

ELwasnotpartoftheJSPstandardpriorto2.0.OneofthemainreasonsforcreatingELwastoensurethatpresentation-levelJSPpagescouldbecreatedwithoutrelyingonscriptingelements.Chapter3,“JSPBasics2:

GeneralizedTemplatingandServerScripting,”coveredtheuseofscriptingelements(typicallycodewritteninJava)thatareembeddedwithinaJSPpage.

TheneedforscriptingelementswithinJSPistypicallydrivenbytherequirementsofanapplication.

Majorapplicationrequirementsthatdemandtheuseofscriptingelementsincludethefollowing:

❑Toprovidecontrol-flowforJSPexecution

❑Toset,andsubsequentlyaccess,variablesthatarelocaltotheJSPpage

❑TorenderavaluefromacomplexexpressionthatinvolvesJavaobjects

❑ToaccesspropertiesofanarbitraryJavaobject

❑TocallmethodsofJavaBeansorotherJavaobjects

Unfortunately,experiencehasshownthattheuseofscriptingelementsinJSPsmakeslargeprojectsdiffi-culttomaintainoverthelongterm.Italsoencouragesprogrammingpracticesthatmaytightlycouplethepresentation(userinterface)ofanapplicationtoitsbusinesslogic,reducingitsflexibilityandscala-bility.ThisisahighlyundesirablepracticeinthecreationofWebapplicationsandservices.Ideally,JSPsshouldbecreatedfreeofscriptingelementsifatallpossible.

InordertocreateaJSPversionthatcanworkcompletelyfreeofscriptingelements,itisessentialthatallfiveoftheapplicationrequirementscanbesatisfiedwithouttheuseofembeddedJavacoding.JSP2.0satisfiestheserequirements.ThefirsttwoitemsarehandledbyJSTL(exploredindetailinChapter6,“JSPTagLibrariesandJSTL”),whilethelastthreerequirementsarehandledbyEL.

ELisindependentofJSP2.0.DespitethevitalroleofELinJSP2.0,theuseofELisnotexclusivetoJSPcontainers.TheELparserisalsonottightlyintegratedintotheJSPparser,butcanbedetachedandreusedforotherpurposes.Infact,ELisincorporatedintobothJavaServerFaces(JSF,aserver-sideGUIconstructionkittechnology;

seeChapter21,“JavaServerFaces,”formoreinformation),andJSTL.Therefore,becomingfamiliarwithELwillsaveyoutimewhenexploringtheseothertechnologies.

ELNamedVariables

WhenworkingwithEL(andJSTL),youwillfrequentlyworkwithnamedvariables.NamedvariablesinELrefertoattributesattachedtoJSPscopingobjects.Forexample,thefollowingELexpressionwillren-derthevalueofthenamedvariablecalledbearCount:

TheELparserwillsearchfortheattributethroughthevariousJSPscopingobjectsinthefollowingorder:

1Page

2.Request

Session(ifcurrentlyvalid)

Application

Inpractice,thisisequivalenttoacalltotheJavaPageContext.findAttribute()method.IfyouaremaintaininglegacyJSPcodewithembeddedJava,youmayseethiscall.YoucanconsulttheJSPJavadocs(APIdocumentation)toseehowthismethodworks.

Figure5-1illustratesthesearchforanELnamedvariable.

Figure5-1:

OrderofsearchforanELnamedvariable

InFigure5-1,youcanseethesearchorderforanELnamedvariable:

FirstthesetofELimplicitobjectsissearchedforamatchingname(ELimplicitobjectsarecoveredlaterinthischapter),andthenthefourscopes.Ifthenamedvariableisnotfound,someactionmaycreateit.

Iftheattributewiththespecifiednamecannotbelocatedinanyscope,anullvalueisreturned.Thenullvaluewillrenderasa“”(emptystring)intheoutput,andwillnottriggeranyerror.

ApplyingEL

Asthenameimplies,theExpressionLanguageworkswithexpressions.Itisaprogramminglanguageusedintheconstructionofexpressions.AllELexpressionsareenclosedinthe${...}notation.TheexpressionisevaluatedbeforetherestoftheJSPisevaluated.YoucanplaceELexpressionsintwoplaceswithinaJSP:

❑Inlinewithtemplatedata

❑WithinattributesofJSPactions,standardorcustom

UsingELexpressionsinlinewithtemplatedata

ThemosttypicaluseofELexpressionsistorenderatextualstringinlinewithtemplatedata.Forexample,considerthefollowingJSPfragment:

<

b>

Thereare${5+1}bearsinthecave.<

/b>

Inthiscase,theELexpressionisplacedinlinewiththeHTMLtemplatedata.AtJSPprocessingtime,theexpression${5+1}willevaluateto6,andbeplacedatthesamepositionastheoriginalexpression.ThiswillresultinthefollowingHTML:

Thereare6bearsinthecave.<

UsingELexpressionsinattributevalues

TheotherplacewhereyouwillseeELexpressionsusediswithintheattributesofcertaintags,includingJSTLtags,standardJSPactions,andcustomtags.

Forexample,considerthefollowingJSPfragmentusingJSTL:

c:

iftest=”${salary>

100000}”>

Richcousin!

br/>

/c:

if>

Inthiscase,theELexpression${salary>

100000}isusedtoconditionallyrenderthebodyoftheJSTLtag.Itisplacedinthetestattributeofthe<

customJSTLaction.ThiswillcausetheELexpressiontobeevaluatedbeforetheJSTLcustomactionisevaluated.TheHTML<

willberenderedonlyifthenamedvariablecalledsalaryisgreaterinvaluethan100,000.

Forexample,considerthefollowingJSPfragmentfeaturingtheJSTL<

set>

tag:

setvar=”datetime”val=’${dateNow}-${timeNow}’/>

IfthedateNownamedvariablecontainsthestring“May1,2005”andtimeNowcontains“11:

00AM”,thentheresultingdatetimenamedvariablewillcontain“May1,2005-11:

00AM”.

Asshownintheprecedingsection,anELexpressioncanbeanarithmeticexpression,oranexpressionfeaturingacomparison.ThefollowingTryItOutsectionexploressomeoftheseELexpressions.

Totryoutthefirstexample,deploych05.wartoyourTomcat5server.ReviewChapter1ifyoudonotrememberhowtodeployaWARfile.

AccessthefollowingURLusingyourbrowsertoseetheexample’soutput:

http:

//localhost:

8080/ch05/example1/

YoushouldseesomethingsimilartowhatisshowninFigure5-2.

Figure5-2:

OutputresultofELexpressions

TheoutputinFigure5-2istheresultofacollectionofdifferentELexpressions.ThefollowingHowItWorkssectionexaminestheELexpressionsusedtogeneratethisoutput.

HowItWorks

TheJSPusedtogeneratetheoutputshowninFigure5-2islocatedat<

TomcatInstallation

Notethatoperatorprecedencehascausedthemultiplicationanddivisiontobeexecutedfirst.Furthermore,thecalculationhascausedadecimaltoappearintheoutput.YoucanusethenumericformattingtagsinJSTLtoeliminatethis.Forexample,thefollowingJSPfragmentinindex.jsprendersthesameresultwith-outthedecimalpoint.

TheformatNumberJSTLtagisusedtoformatthenumericaloutput,usingapatternthatspecifiesnodecimalpointshouldbedisplayed.Thisresultsinthefollowingoutput.

Comparisonoperators

ELsupportstheentirerangeofcomparisonoperatorsfoundinmostprogramminglanguages.Eachoftheoperatorshasasymbolicformandanabbreviatedtextualform.Thefollowingtableenumeratestheavailableoperators.

NotethatinthepreviouscomparisonELalwaysattemptstoconvertthetypeofthedatabeingcom-pared“intherightway.”Thatis,thecharacterdataisconvertedtonumericvaluebeforebeingcom-pared,exceptinthecasewheretwocharactersarecompared.

Inthepreviousexample,theemptystring“”isconsideredemptywhileanyotherstringvalueisnot.Anonexistentvariable,Junk,isgivenanullvalueinEL.Thisnullvalueisconsideredemptywhentestedwiththeemptyoperator.Ontheotherhand,theguessvariableexists(usedearlier)andthereforeisnotempty.Inotherwords,dependingonthedatatypeoftheoperand,theemptyoperatorcanalsobeusedtotestfortheconditionsshowninthefollowingtable.

ThenamedvariableStrVarisinitiallysettothestringtrue.ThisisavariableoftypeString.However,becausethetestattributeoftheJSTL<

tagrequiresaBooleanexpression,itisautomaticallycon-vertedtoaBooleanbyELbeforeuse.Thiscausestheprintingofthe“equal!

”message.

Finally,thecomparisonoperatorisbeingusedonthespecialnullvalue.Itisshown

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > IT计算机 > 电脑基础知识

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2