ognl

How to compare two strings using Struts2 tags and OGNL?

只谈情不闲聊 提交于 2019-12-03 14:13:00
I am trying to compare two values : one from session and anther from iterator <s:iterator value="themes" status="currentRecord"> <s:if test="%{usertheme}) == %{themeName}"> <td align="center" bgcolor="red"> </s:if> <s:else> <td align="center" bgcolor="green"> </s:else> </s:iterator> But I am unable to compare my values, please can you tell me where I am doing mistakes ? %{} should be put (if necessary) around all the statement, not in the middle. For Strings you should use .equals , .equalsIgnoreCase , .contains , .indexOf etc... Not == . Change to this: <s:iterator value="themes" status=

Format number in Struts 2 <s:property/> tag

佐手、 提交于 2019-12-03 06:51:17
问题 I would like to format number displayed by <s:property value="summary.total"/> tag in Struts 2. There is a double value. How can I do that? Should I use OGNL ? Or maybe I must use <s:text/> tag and define my format in resuource file? 回答1: You need to use <s:text/> with <s:param/> . Property file: summary.cost= € {0,number,##0.00} JSP: <s:text name="summary.cost"> <s:param name="value" value="summary.total"/> </s:text> This answer explains how to use # and 0 in the format mask. 回答2: The way

Struts2_ValueStack,OGNL详解

一笑奈何 提交于 2019-12-03 01:54:43
一、ValueStack 1 .ValueStack是一个接口,在struts2中使用OGNL(Object-Graph Navigation Language)表达式实际上是使用 实现了ValueStack接口的类OgnlValueStack.它是ValueStack的默认实现类. 2 .ValueStack贯穿整个action的生命周期,每一个action实例都拥有一个ValueStack对象,其中保存了当前action对象和其他相关对象. 3 .struts2把ValueStack对象保存在名为:struts.valueStack的request域中.即ValueStack作用域为request.当action创建的时候,ValueStack就创建了,action被销毁的时候,ValueStack就销毁了 4 .ValueStack中的数据分两部分存放:root(栈结构,CompoundRoot)和context(map形式,OgnlContext) (1) * 其中的root对象是CompoundRoot,CompoundRoot继承了ArrayList,提供了额外的方法:push(),和pop()方法, 用来对root对象中所包含的数据进行存取.正是由于这两个方法,CompoundRoot变成了一个栈结构. * struts2中,一个请求在最终到达Action的方法之前

OGNL表达式的用法#,%,$

匿名 (未验证) 提交于 2019-12-03 00:27:02
1.1获取context中的数据 < body > < h1 > #号的 </ h1 > < h3 > 获取context中的数据 </ h3 > <% request .setAttribute( "name" , "张三" ); %> < s:property value = "#request.name" /> </ body > 1.2使用#构建List集合 < s:iterator value = "list" > </ s:iterator > 如果想上面直接这样写的话,是从值栈中取值的 构建List集合: < s:iterator value = "{'aa','bb','cc'}" var = "i" > < s:property value = "i" /> <!-- 能将list中的数据遍历出来 --> </ s:iterator > <!-- 因为使用了var="i" ,这个i只要定义了,那么context区里也有,所以还可以使用下面的方法取值 --> < s:iterator value = "{'aa','bb','cc'}" var = "i" > < s:property value = "#i" /> <!-- 这是直接从context中取值 --> </ s:iterator > <!-- 还可以从context域中取值 因为定义了var=

Struts2学习-3 : OGNL表达式详解

匿名 (未验证) 提交于 2019-12-03 00:26:01
OGNL表达式详解 1,OGNL:Object Graph Navigation Language 2,OGNL不仅可以调用属性,还可以调用普通方法 < s:property value = '"abcdefg".toCharArray()[0]' />< br /> < s:property value = "#context['com.opensymphony.xwork2.ActionContext.locale']" /> < s:property value = "11111111111111111H" />< br /> 3:OGNL获取属性等 <% request.setAttribute( "str" new "a" , "b" , "c" }); %> < s:debug ></ s:debug > < s:property value = "#request.str.length" />< br /> < s:property value = "#request.str['length']" />< br /> < s:property value = "#request.str['len'+'gth']" />< br /> 4.1链式表达式(Chained Subexpressions): < s:property value = " 110H

mybatis 使用ognl

匿名 (未验证) 提交于 2019-12-03 00:02:01
@Ognl @isNotEmpty() for String,Array,Collection,Map Test now, test empty string test. must use: <if test="userId != null && ''.equals(userId)"> and user_id = #{userId} </if> but, OGNL support Calling Static Methods. http://www.opensymphony.com/ognl/html/LanguageGuide/staticMethods.html so, we can use this for test empty String,Array,Collection,Map. look like this: <if test=" @Ognl @isNotEmpty(userId)"> and user_id = #{userId} </if> source code: public class Ognl { /** * test for Map,Collection,String,Array isEmpty * @param o * @return */ public static boolean isEmpty(Object o) throws

Struts笔记5

匿名 (未验证) 提交于 2019-12-02 21:45:52
文件下载 1.写action类 package com.gyf.web.action; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import com.opensymphony.xwork2.ActionSupport; public class DownloadAction3 extends ActionSupport { private InputStream is; public InputStream getInputStream() { return is; } public String download() throws FileNotFoundException{ String path = "C:/Users/Yuan/Desktop/9.png"; //给输入流赋值 is = new FileInputStream(path); return SUCCESS; } } 2.配置struts.xml 查看源码发现要以流的方式返回给客户端需要配置3个参数 <action name="download" class="com.gyf.web.action

Sturts2中的OGNL

时光毁灭记忆、已成空白 提交于 2019-12-02 21:02:32
参考 http://struts.apache.org/2.x/docs/ognl-basics.html 和 http://struts.apache.org/2.x/docs/ognl.html OGNL——Object Graph Navigation Language,参考 http://www.ognl.org/ 一.Xwork的OGNL 在Struts2里边的OGNL是基于XWork的。XWork的OGNL和普通意义上的OGNL有一些差别,首先最大的差别就是OGNL只提供了一个根对象(root),而Xwork提供了一个ValueStack,这是Struts2的OGNL的默认root。另外,XWork提供了自己独特的OGNL PropertyAccessor自动从顶向下的查找Stack中符合条件的对象属性。 比如说,有两个对象Animal和Person,两个对象都提供了name属性,同时Animal有species属性,Person有salary属性。假定Animal在stack的顶端。 species // call to animal.getSpecies() salary // call to person.getSalary() name // call to animal.getName() because animal is on the top

Format number in Struts 2 <s:property/> tag

前提是你 提交于 2019-12-02 19:27:12
I would like to format number displayed by <s:property value="summary.total"/> tag in Struts 2. There is a double value. How can I do that? Should I use OGNL ? Or maybe I must use <s:text/> tag and define my format in resuource file? Trick You need to use <s:text/> with <s:param/> . Property file: summary.cost= € {0,number,##0.00} JSP: <s:text name="summary.cost"> <s:param name="value" value="summary.total"/> </s:text> This answer explains how to use # and 0 in the format mask. The way more fast <s:property value="getText('{0,number,#,##0.00}',{summary.total})"/> Lucky!! This one is quicker:

How could I get a parameter in JSP?

孤人 提交于 2019-12-02 17:52:57
问题 Here is my action execute() method, @Override public String execute() throws Exception { ActionContext aContext = ActionContext.getContext(); aContext.getParameters().put("reqVar1", "reqVar1-Value"); return SUCCESS; } I want to get the parameter value in JSP like below code, <s:property value="#parameters.reqVar1" /> but it doesn't work. I see the parameter is in stack context: How could I get the parameter value in JSP? 回答1: Parameters are always use a type Map<String, String[]> . And you