ognl

Accessing static variable using OGNL in Struts2

情到浓时终转凉″ 提交于 2019-12-05 03:27:06
Good day! I am reading Manning's struts2 book and one of the topic is accessing the static variable using OGNL using the syntax @[fullClassName]@[property or methodCall] so I tried it on my program and my code is as follows: BEAN: public class ContactsBean { private static int count = 1; //getter and setter } ACTION: private ContactsBean contacts; //getters and setters JSP: <s:property value="@com.demo.bean.ContactsBean@count" /> or <s:property value="@vs@count" /> //valuestack method but it doesn't work. Am i missing something? Thank you. @see OGNL Basics : Accessing static properties BEAN :

How to compare two strings using Struts2 tags and OGNL?

感情迁移 提交于 2019-12-04 22:28:26
问题 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 ? 回答1: %{} should be put (if necessary) around all the statement, not in the middle. For Strings you should use .equals ,

Retaining values between multiple JSPs and Actions in Struts 2

余生颓废 提交于 2019-12-04 19:02:09
My struts project structure is as follows: page1 -> action1 -> page2 -> action2 -> page3 What i need is for a value i entered in an input tag in page1 to be accessed in action2. Here is my code: page1: <div class = "container"> <s:form id = "idinput" method = "post" action = "idEntered"> Enter id: <input id = "txtid" name = "txtid" type = "text" /> <input id = "cmdsubmit" name = "cmdsubmit" type = "submit" value = "enter details" /> </s:form> </div> action1: public class AddId extends ActionSupport { private int txtid; //getter and setter @Override public String execute() throws Exception {

how can i use request parameter in struts2 if tag

a 夏天 提交于 2019-12-04 17:43:33
i have a link like this : http://localhost:8080/ESA/login.jsp?login=failed in end of above link a set a parameter with name login and value failed . how i can use this parameter in jsp page with struts if tag. I use following code but it don't work. <s:if test="%{#parameters.login='failed'}"> <div class="error"> <s:text name="user.login.failed"></s:text> </div> </s:if> Try with <s:if test="%{#parameters.login[0]=='failed'}"> The two problems were in your code: The = sign is an assignment, not equals == ; Parameters are saved in the Map<String, String[]> , so each parameter could have multiple

Pass Arraylist from Java class and fetch it in JSP page In Struts 2

佐手、 提交于 2019-12-04 07:00:46
问题 I am trying to get ArrayList in JSP page passed from java class. But eventually I didn't succeed. Here is what I have done. Here is my POJO class: public class Coordinates { private double latitude; private double longitude; public double getLatitude() { return latitude; } public void setLatitude(double latitude) { this.latitude = latitude; } public double getLongitude() { return longitude; } public void setLongitude(double longitude) { this.longitude = longitude; } } And this one is Java

How to pass parameter to method call in Struts 2 OGNL

冷暖自知 提交于 2019-12-04 05:45:32
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. Ah, the joy of %#$ in OGNL... This doesn't work ? <s:iterator value="%{order.getProductById(orderProductId).activations}"> 来源: https://stackoverflow.com/questions/2945684/how-to-pass-parameter-to-method-call-in-struts-2-ognl

struts2学习笔记

拥有回忆 提交于 2019-12-04 05:39:12
Struts2学习笔记 1.Struts2 简介 1.1 Struts2概念 Struts2是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet,在MVC设计模式中,Struts2作为控制器(controller)来建立模型与视图的数据交互。Struts2是Struts2的下一代产品,这个框架充分发挥了Struts2和WebWork这两种技术的优势,抛弃原来Struts1的缺点,使得Web开发更加容易。 1)、运行在web层.负责处理请求的. 2)、struts2已经帮我们封装了很多web中常用的功能(拦截器) 3)、struts2 与 struts1 没什么关系. struts2是基于webwork框架 1.2 Struts2的优点 项目开源,使用及扩展方便; 提供Exception处理机制; Result方式的页面导航,通过Result标签很方便的实现重定向和页面跳转; 通过简单、集中的配置来调度业务类,使得配置和修改都非常容易; 提供简单、统一的表达式语言来访问所有可供访问的数据; 提供标准、强大的验证框架和国际化框架; 提供强大的、可以有效减少页面代码的标签; 提供良好的Ajax支持; 拥有简单的插件,只需要放入响应的jar包,任何人都可以扩展Struts2框架 1.3 Struts2与Servlet比较 优点:业务代码解耦,提高开发效率

configure request param for action to be assigned to fields of bean

一曲冷凌霜 提交于 2019-12-04 01:48:45
问题 I am using www.datatables.net . JS framework to show data in tables. It has server mode and it sends a lot of params during this mode. Example: sortColumn , sortType(asc,desc) , filter values, pagenum , itemsonpage and so on. So i handle it in action. i assign to each request param field in action and it work fine. But now i have several table. So i have to make different actions but request params same and there are a lots of them. It is not a good idea to copy paste code from one action to

Struts2学习整理

…衆ロ難τιáo~ 提交于 2019-12-04 00:31:42
Struts2的相关配置文件 * default.properties -- 在org/apache/struts2/目录下,代表的是配置的是Struts2的常量的值 * struts-default.xml -- 在Struts2的核心包下,代表的是Struts2核心功能的配置(Bean、拦截器、结果类型等) * struts-plugin.xml -- 配置插件的信息 * struts.xml -- 重点中的重点配置,代表WEB应用的默认配置,可以配置常量,基本就配置它就可以 * struts.properties -- 该文件是Struts的默认配置文件 (可以配置常量 ) * web.xml -- 配置前端控制器(可以配置常量) 注意:后加载的配置文件会覆盖掉之前加载的配置文件(在这些配置文件中可以配置常量) Struts2核心配置文件Struts2.xml的配置入门 <package>标签 如果要配置<Action>的标签,那么必须要先配置<package>标签,代表的包的概念。 包含的属性 name 包的名称,要求是唯一的,管理action配置。 extends 继承,可以继承其他的包,只要继承了,那么该包就包含了其他包的功能,一般都是继承struts-default namespace 名称空间,一般与<action>标签中的name属性共同决定访问路径

刨根问底-struts和ognl密切分析

孤街醉人 提交于 2019-12-04 00:27:58
前面的2篇文章已经详细的分析了ognl获取数据的过程和设置数据的过程。其中最重要的点是ognl的三要素: (1) 表达式(Expression) 表达式是整个OGNL的核心,所有的OGNL操作都是针对表达式的解析后进行的。 简介的概括“干什么” (2) 根对象(Root Object) 根对象可以理解为OGNL的 操作对象 。 简介的概括“对谁干” 或者“对谁操作” (3) 上下文环境(Context) OGNL的内部,所有的操作都会在一个特定的环境中运行, 简介的概括“在哪干” 或者“在哪操作” 如果明白了ognl的三要素,下面就好理解了。 《 刨根问底-struts-serviceAction()创建并执行action 》中分析了执行action方法之前,循环执行拦截器,其中 ParametersInterceptor拦截器主要工作:把jsp中传来的数值赋值到action类中的属性 。现在就看看 ParametersInterceptor类 doIntercept()方法 1、ParametersInterceptor类doIntercept()代码: @Override public String doIntercept(ActionInvocation invocation) throws Exception { Object action = invocation