您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 销售管理 > Struts2.1 OGNL 表达式
@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%2.%@pageimport=com.rao.struts2.bean.Sex%3.%@taglibprefix=suri=/struts-tags%4.!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//EN5.html6.head7.titleMyJSP'OGNL1.jsp'startingpage/title8.9.metahttp-equiv=pragmacontent=no-cache10.metahttp-equiv=cache-controlcontent=no-cache11.metahttp-equiv=expirescontent=0=keywordscontent=keyword1,keyword2,keyword313.metahttp-equiv=descriptioncontent=Thisismypage14.!--15.linkrel=stylesheettype=text/csshref=styles.css16.--17.18./head19.20.body21.%22.request.setAttribute(req,requestscope);23.request.getSession().setAttribute(sess,sessionscope);24.request.getSession().getServletContext().setAttribute(app,);26.%27.1.通过ognl表达式获取属性范围中的值28.br29.s:propertyvalue=#request.req/30.br/31.s:propertyvalue=#session.sess/32.br/33.s:propertyvalue=#application.app/34.br/35.hr36.2.通过SPANstyle=BACKGROUND-COLOR:#fafafaognl表达式创建list集合,并且遍历出集合中的值37.br=listvalue={'eeeee','ddddd','ccccc','bbbbb','aaaaa'}/s:set39.s:iteratorvalue=#listvar=o40.!--${o}br/--41.s:property/42.br/43./s:iterator44.br/45.hr46.3.通过ognl表达式创建Map集合,并且遍历出集合中的值47.br48.s:setname=map49.value=#{'1':'eeeee','2':'ddddd','3':'ccccc','4':'bbbbb','5':'aaaaa'}/s:set50.s:iteratorvalue=#mapvar=o!--${o.key}-${o.value}br/--52.!--s:propertyvalue=#o.key/-s:propertyvalue=#o.value/br/--53.s:propertyvalue=key/-s:propertyvalue=value/54.br/55./s:iterator56.br/57.hr58.4.通过ognl表达式进行逻辑判断59.br60.s:iftest='aa'in{'aaa','bbb'}61.aa在集合{'aaa','bbb'}中;62./s:if63.s:else不在集合{'aaa','bbb'}中;65./s:else66.67.br/68.69.s:iftest=#request.reqnotin#list70.不在集合list中;71./s:if72.s:else73.在集合list中;74./s:else75.br/76.hr77.5.通过ognl表达式的投影功能进行数据筛选78.br79.s:setname=list1value={1,2,3,4,5}/s:set=#list1.{?#this2}var=o81.!--#list.{?#this2}:在list1集合迭代的时候,从中筛选出当前迭代对象2的集合进行显示--82.${o}br/83./s:iterator84.br/85.hr86.5.通过ognl表达式访问某个类的静态方法和值87.br88.s:propertyvalue=@java.lang.Math@floor(32.56)/89.90.s:propertyvalue=@com.rao.struts2.action.OGNL1Action@aa/91.br/92.br/93.hr94.6.ognl表达式迭代标签详细=list297.value={'aa','bb','cc','dd','ee','ff','gg','hh','ii','jj'}/s:set98.tableborder=199.tr100.td101.索引102./td103.td104.值105./td106.td107.奇?108./td偶?111./td112.td113.首?114./td115.td116.尾?117./td118.td119.当前迭代数量120./td121./tr=#list2var=ostatus=s123.trbgcolor=s:iftest=#s.evenpink/s:if124.td125.s:propertyvalue=#s.getIndex()/126./td127.td128.s:property/129./td130.td131.s:iftest=#s.oddY/s:if:else133./td134.td135.s:iftest=#s.evenY/s:if136.s:elseN/s:else137./td138.td139.s:iftest=#s.firstY/s:if140.s:elseN/s:else141./td142.td=#s.isLast()Y/s:if144.s:elseN/s:else145./td146.td147.s:propertyvalue=#s.getCount()/148./td149./tr150.151./s:iterator152./table153.br154.hr表达式:if/elseif/else详细br156.%request.setAttribute(aa,0);%157.s:iftest=#request.aa=0&request.aa=4158.在0-4之间;159./s:if160.s:elseiftest=#request.aa=4&request.aa=8161.在4-8之间;162./s:elseif163.s:else164.大于8;165./s:else166.br167.hr168.8.ognl表达式:url详细br169.%request.setAttribute(aa,sss);%170.s:urlaction=testActionnamespace=/aa/bb=aavalue=#request.aa/s:param172.s:paramname=id100/s:param173./s:url174.br/175.s:setname=myurlvalue=':set176.value以字符处理:s:urlvalue=#myurl/s:urlbr177.value明确指定以ognl表达式处理:s:urlvalue=%{#myurl}/s:url178.br179.hr180.9.ognl表达式:checkboxlist详细br181.1.list生成;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~br的名字br183.list:checkboxlist要显示的列表br184.value:checkboxlist默认被选中的选项,checked=checkedbr185.s:checkboxlistname=checkbox1list={'上网','看书','爬山','游泳','唱歌'}value={'上网','看书'}/s:checkboxlist186.br187.以上生成代码:br188.xmp189.inputtype=checkboxname=checkbox1value=上网id=checkbox1-1checked=checked/190.labelfor=checkbox1-1class=checkboxLabel上网/label191.inputtype=checkboxname=checkbox1value=看书id=checkbox1-2checked=checked/=checkbox1-2class=checkboxLabel看书/label193.inputtype=checkboxname=checkbox1value=爬山id=checkbox1-3/194.labelfor=checkbox1-3class=checkboxLabel爬山/label195.inputtype=checkboxname=checkbox1value=游泳id=checkbox1-4/196.labelfor=checkbox1-4class=checkboxLabel游泳/label197.inputtype=checkboxname=checkbox1value=唱歌id=checkbox1-5/198.labelfor=checkbox1-5class=c
本文标题:Struts2.1 OGNL 表达式
链接地址:https://www.777doc.com/doc-3364154 .html