ognl

Creating dynamic URL with 2 action parameters in Struts 2 using OGNL [duplicate]

怎甘沉沦 提交于 2019-11-27 04:44:18
问题 This question already has answers here : Passing parameters in URL without query string in Struts 2 (2 answers) Closed 2 years ago . If I have a url: www.myurl.com/books and want to be able to create new <s:url> filtering on author and year: www.myurl.com/books/Sartre/1942 by passing Sartre and 1942 as parameters to the action class which will render the books page with the appropriate results. How to do this in Struts2? I have the backend logic in place so it would be great if: I could reuse

OGNL, JSTL, STRUTS2标签中符号#,$,%的用法示例

◇◆丶佛笑我妖孽 提交于 2019-11-27 04:19:25
取Session中的值 <c:out value="${sessionScope.user.userId}"></c:out><br> <c:out value="${user.userLoginName}"></c:out><br> <s:property value="#session.user.userId"/><br> ${session.user.userId}<br> ${sessionScope.user.userId}<br> 基本语法 一、EL简介 1.语法结构 ${expression} 2.[]与.运算符 EL 提供.和[]两种运算符来存取数据。 当要存取的属性名称中包含一些特殊字符,如.或?等并非字母或数字的符号,就一定要使用 []。例如: ${user.My-Name}应当改为${user["My-Name"] } 如果要动态取值时,就可以用[]来做,而.无法做到动态取值。例如: ${sessionScope.user[data]}中data 是一个变量 3.变量 EL存取变量数据的方法很简单,例如:${username}。它的意思是取出某一范围中名称为username的变量。 因为我们并没有指定哪一个范围的username,所以它会依序从Page、Request、Session、Application范围查找。 假如途中找到username,就直接回传

struts2标签#、%、$取值

自闭症网瘾萝莉.ら 提交于 2019-11-27 04:18:55
转载: http://www.cnblogs.com/xly1208/archive/2011/11/19/2255500.html http://www.cnblogs.com/duqiao/archive/2012/11/06/2756447.html 首先了解下 OGNL的概念 : OGNL是 Object-Graph Navigation Language的缩写,全称为 对象图导航语言,是一种功能强大的表达式语言,它通过简单一致的语法,可以任意存取对象的属性或者调用对象的方法,能够遍历整个对象的结构图,实现对象属性类型的转换等功能。 此外,还得先需弄懂OGNL的一些知识: 1.OGNL表达式的计算是围绕OGNL上下文进行的。 OGNL上下文实际上就是一个Map对象,由ognl.OgnlContext类表示。它里面可以存放很多个JavaBean对象。它有一个上下文根对象。 上下文中的根对象可以直接使用名来访问或直接使用它的属性名访问它的属性值。否则要加前缀“#key”。 2.Struts2的标签库都是使用OGNL表达式来访问ActionContext中的对象数据的。如:<s:propertyvalue="xxx"/>。 3.Struts2将ActionContext设置为OGNL上下文,并将值栈作为OGNL的根对象放置到ActionContext中。 4.值栈

Repopulate ArrayList from JSP with Struts 2

会有一股神秘感。 提交于 2019-11-27 04:07:49
问题 This is the form I am using to repopulate the ArrayList <form method = "POST" action = "addItemsToTemplate"> <s:iterator value = "myQuestions" var = "quizItem" status="key"> <s:textfield name = "quizItem.question"/> </s:iterator> <input type = "submit" value = "submit"/> </form> This is the action class public class QuizTest extends ActionSupport{ public String execute(){ List<Question> q= myQuestions; System.out.println(myQuestions); return "success"; } public String populateQuestions(){ /

Struts 2 “%” sign and '#" sign in OGNL

拥有回忆 提交于 2019-11-27 01:25:11
问题 Anybody can tell me how to use "%" and "#" sign in STRUTS2 OGNL? I google around, but can't find any valuable info about this.Or give me a link of documentation of this. thanks 回答1: The % character forces OGNL evaluation, so <s:property name="%{foo}"/> will query the stack for a foo property. It's not always required (rarely, in fact), but it's easier to use it consistently for clarity. The # character accesses a named value stack context variable, for example, you used to need it to access a

Struts2 passing variables case

大城市里の小女人 提交于 2019-11-26 23:13:08
I'm using Datatables server side ajax pagination and need to pass some variables to server. My server is running Struts2 actions to handle this datatables requests. I'm facing some problems because datatables is passing predefined internal variables (like iDisplayStart, iDisplayLength, iColumns, sSearch), but Struts2 cannot receive this kind of camelcase style (just first one char lower and second upper case). To ensure this, I created this test action: @Action (value = "dummy", results = { @Result(name="ok", type="httpheader", params={"status", "200"}) } ) @ParentPackage("default") public

Passing parameters to action through ModelDriven in Struts 2

醉酒当歌 提交于 2019-11-26 23:09:11
The issue is related to the ModelDriven and Struts 2.3.16. Since the behavior of the params interceptor changed to access parameters passed to the action requires to configure acceptParamNames list to use with ModelDriven action. If acceptParamNames list is empty, it works by default accepting params via default pattern. Suppose we have a ModelDriven action: @Namespace("/modelDriven") public class ModelDrivenAction extends ActionSupport implements ModelDriven { private Gangster model = new Gangster(); private String name; //getter and setter public Object getModel() { return model; } @Actions(

Struts 2 nesting iterators

独自空忆成欢 提交于 2019-11-26 17:13:48
问题 I can't believe how something this simple can seem so hard to do in Struts 2. This is approximately what I would like to do as it would be done in Java. for (Parent parent : parents){ for (Child child: parent.getChildren()){ System.out.println(child.getName()); } } That should translate to something close to this in Stuts tags: <s:iterator var="parent" value="parents"> <s:iterator var="child" value="parent.children"> <s:property value="child.name"/> <s:iterator> <s:iterator> I assume parent

How to insert a value into Set collection in Struts 2

瘦欲@ 提交于 2019-11-26 16:48:16
问题 I am doing a project using Struts2 and I have a problem assigning a set collection. Here's my Action (I eliminated the irrelevant part) public class TeamAction extends BaseAction implements ModelDriven<Team> { Team team=new Team(); } Here's my model Team (I eliminated the irrelevant part) private TeamId id; private Set students = new HashSet(0); Here's my JSP part <input type="text" name=team.student[0].id /> Now the problem is I can't insert the right value into this Set collection in by

What&#39;s the difference between # , % and $ signs in Struts tags?

此生再无相见时 提交于 2019-11-26 14:53:33
I'm working with Struts2 and when I'm accessing value stack variables I don't know whether to use % or # or $ . I try all of them until I find the correct one. Can Anybody Explain what is the difference between these? Use of # (pound sign) OGNL is used to refer to objects in the ActionContext as follows: objectName : object in the ValueStack (default/root object in the OGNL context), such as an Action property #objectName : object in the ActionContext but outside of the ValueStack, specifically... #objectName : ActionContext object that has been created using the Struts2 data tags with the