ognl

Prevent getText() evaluating EL expressions

冷暖自知 提交于 2019-12-06 04:50:18
In Struts2 backend, I have an action class instance variable, eg: keyName . A dynamic key returned to view(JSP). This keyName variable is set using a request parameter using POST method. Depending on the request parameter value, the keyName will vary. In JSP, I am using <s:property value="getText(keyName)" /> to show the label corresponding to the key given by keyName variable. When I send an EL expression for example ${90-40} to keyName this expression is being evaluated and resulting in showing 50 on the UI. How can we avoid or prevent such EL injection with getText() ? Is there any other

Struts 2 - Understanding the working between OGNL and params interceptor

醉酒当歌 提交于 2019-12-06 04:43:30
I am new to Struts 2. I am studying it from the book Struts2 In Action. I am having difficulty in understanding some concepts in OGNL which are as follows- We know that params interceptor moves the data from the request parameters to the action object in ValueStack . Now while reading, I came upon a line that says- "The tricky part of the job is mapping the name of the parameter to an actual property on the ValueStack . This is where OGNL comes in. The params interceptor interprets the request parameter name as an OGNL expression to locate the correct destination property on the ValueStack".

Struts2值栈和OGNL

混江龙づ霸主 提交于 2019-12-06 02:29:50
一、首先关于Struts2框架: ①特点: 1、通用性 2、可扩展性 struts2可以自定义类型转换器(尚待深入)、自定义拦截器。 3、非侵入式 不会污染其他模块 ②配置 1、Web工程的web.xml文件配置filter拦截器(拦截*.action请求) 2、struts.xml首先要关联约束文档 <package name="default" namespace="/" extends="strutd-default"> <action name="saveBook" class="com.atguigu.bean.Book" method="save"> <result name="toDetailPage">detailpage.jsp</result> </action> </package> 标签package的作用是定义一个功能模块,其name属性作为标识是必填项,便于其他package引用,extends是继承了默认的配置。namespace也采用了默认配置,如果采用自定义名称空间,则访问这个package中定义的action时,必须在路径中加上名称空间值。 action对应着请求,class属性指定处理请求的类,method属性为处理请求的具体方法,result则对应响应,注意其name属性值。 ③Action类 类中的set方法是注入请求参数

How to pass parameter to method call in Struts 2 OGNL

三世轮回 提交于 2019-12-05 22:47:08
问题 I want to use a property as a param of an object's method. <s:property value="orderProductId" /> returns correct value (e.g. 1) <s:iterator value="%{order.getProductById(1).activations}"> gives me correct value too. But <s:iterator value="%{order.getProductById(#orderProductId).activations}"> doesn't. Not sure why #orderProductId doesn't interpret correctly. 回答1: Ah, the joy of %#$ in OGNL... This doesn't work ? <s:iterator value="%{order.getProductById(orderProductId).activations}"> 来源:

How data travels in Struts2?

≡放荡痞女 提交于 2019-12-05 19:20:59
I am trying to understand the path data takes within Struts2, how is data placed on the ValueStack? How can I find out which object is currently present in the ValueStack? What other data can I access from different scopes application, session, request, page? How to decide the scopes my variables should have? Dave Newton That's a lot of questions. The value stack is just a data structure, sort of a combination of a map and stack. Named objects (accessed via the # tag in OGNL) are in the map (like the request scope, say), objects to search through for properties/methods are on the stack. The <s

Ognl 语法基础教程

半城伤御伤魂 提交于 2019-12-05 18:29:56
本文将力求用最简单的语言和实例,介绍一下 OGNL 的语法规则,文章主要内容参考自官方文档 http://commons.apache.org/proper/commons-ognl/language-guide.html 本篇主要是语法介绍篇,实战放在一下篇 因为本篇文章将是后 quick-fix 2.0 版本支持 ognl 的前导篇,先提前放出 <!-- more --> 1. 前言 ognl,全称 Object Graphic Navigation Language(对象图导航语言),根据约定的一些简单的规则,组装一个利于阅读、可执行的表达式语句 如下面是一个典型的表达式 "name".toCharArray()[0].numericValue.toString() 即便完全不懂 ognl,单纯的以 java 的基础知识就可以看懂,而这就是 ognl 的魅力所在 (学习一点点东西,就可以马上入手) 2. 对象定位 说明,这一小节的内容为我个人为了方便理解而分类的,并不官方 我们知道在 java 中,一切都是对象,所以我们的 ognl 表达式必然是着手于某一个对象的,通常在 ognl 中,可以将待执行目标对象划分为三类 简单对象:(如基本数据类型,String) 非简单对象:(非简单对象,实例访问) 静态对象:(静态类) 在 gonl 的语法中,上面三种 case

Ognl 语法基础教程

大兔子大兔子 提交于 2019-12-05 18:01:09
本文将力求用最简单的语言和实例,介绍一下 OGNL 的语法规则,文章主要内容参考自官方文档 http://commons.apache.org/proper/commons-ognl/language-guide.html 本篇主要是语法介绍篇,实战放在一下篇 因为本篇文章将是后 quick-fix 2.0 版本支持 ognl 的前导篇,先提前放出 <!-- more --> 1. 前言 ognl,全称 Object Graphic Navigation Language(对象图导航语言),根据约定的一些简单的规则,组装一个利于阅读、可执行的表达式语句 如下面是一个典型的表达式 "name".toCharArray()[0].numericValue.toString() 即便完全不懂 ognl,单纯的以 java 的基础知识就可以看懂,而这就是 ognl 的魅力所在 (学习一点点东西,就可以马上入手) 2. 对象定位 说明,这一小节的内容为我个人为了方便理解而分类的,并不官方 我们知道在 java 中,一切都是对象,所以我们的 ognl 表达式必然是着手于某一个对象的,通常在 ognl 中,可以将待执行目标对象划分为三类 简单对象:(如基本数据类型,String) 非简单对象:(非简单对象,实例访问) 静态对象:(静态类) 在 gonl 的语法中,上面三种 case

Accessing action instance variables and model-driven bean variable values in JSP

纵饮孤独 提交于 2019-12-05 17:19:54
I have searchKey as a variable in action class and model-driven bean object. public class PaymentGateWayAction extends ActionSupport implements ModelDriven<PaymentResponseDTO> { private String searchKey; private PaymentResponseDTO paymentResponseDTO = new PaymentResponseDTO(); // ... } searchKey is also a variable in PaymentResponseDTO . I need to access searchKey from the action class and modeldriven bean based on some conditions. Having varible with same name is bad. But The above one is already developed. If I do any modification in Java file, I need to do many modifications which are

To access the index value of struts iterator in scriptlet array index

我是研究僧i 提交于 2019-12-05 07:35:57
I am a newbie in web development. Using Struts2, I have a comma separated String of my images captions. While iterating the images to render on JSP I need to display caption along with specific images and could not get any specific tag to split caption String over delimiter and to access specific caption. I am trying the below code and don't know what to use in place of something to get the current iteration index in iterator. <s:iterator value="images" status="incr"> <%= ((String)request.getAttribute("imageCaptionsString")).split(",")[something]%> </s:iterator> I know that using scriptlets

Struts 2 s:select with values from resource bundle

无人久伴 提交于 2019-12-05 07:00:13
We are using the s:select to show a list of string from resource bundle. In the Action: //bank codes will be something [12,13,14] List<String> bankCodesList; //with setter and getter String selectedBankCode; In the message resources each bank will have a name: bank.code.12= ALFM Bank bank.code.13= RIHN Bank .... In the JSP: <s:select name = "selectedBankCode" list = "bankCodesList" listKey = "toString()" listValue = "%{getText('bank.code.' + toString())}" /> As the bank list is List<String> we used toString() to get the key and used toString() to get value from resource bundle. I excepted to