struts中#、%和$这三个符号的使用方法(很实用的)
<span class="Apple-style-span" style="color: rgb(50, 62, 50); font-family: simsun; line-height: 21px; ">struts中#、%和$这三个符号的使用方法【摘自max struts2教程】</span><div id="sina_keyword_ad_area2" class="articalContent" style="color: rgb(50, 62, 50); width: 690px; clear: both; padding-top: 18px; font-size: 14px; line-height: 21px; padding-bottom: 30px; word-wrap: normal; word-break: normal; overflow-x: hidden; overflow-y: hidden; font-family: simsun; "><table style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; line-height: normal; width: 690px; table-layout: fixed; "><tbody><tr><td style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-size: 12px; font-family: Verdana, 宋体, sans-serif; line-height: 18px; "><div><div>一、"#"的用法<br> 1、 访问OGNL上下文和Action上下文,#相当于ActionContext.getContext();下表有几个ActionContext中有用的属性:<br><br> parameters 包含当前HTTP请求参数的Map #parameters.id作用相当于request.getParameter("id")<br><br> request 包含当前HttpServletRequest的属性(attribute)的Map #request.userName相当于request.getAttribute("userName")<br><br> session 包含当前HttpSession的属性(attribute)的Map #session.userName相当于session.getAttribute("userName")<br><br> application 包含当前应用的ServletContext的属性(attribute)的Map #application.userName相当于application.getAttribute("userName")<br><br> attr 用于按request > session > application顺序访问其属性(attribute) #attr.userName相当于按顺序在以上三个范围(scope)内读取userName属性,直到找到为止<br><br> 2、用于过滤和投影(projecting)集合,如books.{?#this.price<100};<br><br> 3、构造Map,如#{'foo1':'bar1', 'foo2':'bar2'}。<br><br>二、"%"的用法<br><br> “%”符号的用途是在标志的属性为字符串类型时,计算OGNL表达式的值。例如在Ognl.jsp中加入以下代码:<br><br> <h3>%的用途</h3><br> <p><s:url value="#foobar['foo1']" /></p><br> <p><s:url value="%{#foobar['foo1']}" /></p><br><br>三、"$"的用法<br><br> 1、用于在国际化资源文件中,引用OGNL表达式<br><br> 2、在Struts 2配置文件中,引用OGNL表达式<br><br> 例如:<br> <action name="AddPhoto" class="addPhoto"><br> <interceptor-ref name="fileUploadStack" /> <br> <result type="redirect">ListPhotos.action? albumId=${albumId}</result><br> </action></div></div></td></tr></tbody></table></div>
页:
[1]