ognl

Struts2 的ModelDriven 二——ModelDrive

…衆ロ難τιáo~ 提交于 2019-11-30 07:50:17
继上篇 博客 介绍了值传递的几种形式,这篇博客,来说说struts2是如何实现的? 有这么两个概念和modelDriven实现有关:ValueStack,ModelDrivenInterceptor。 一、ModelDrivenInterceptor 首先先介绍以下ModelDrivenInterceptor,该拦截器处于defaultStack第九的位置。ModelDrivenInterceptor拦截器主要做的事就是调用Action的getModel()方法然后把返回的model压入值栈。 下面是该拦截器intercept方法源码: public class ModelDrivenInterceptor extends AbstractInterceptor { protected boolean refreshModelBeforeResult = false; public void setRefreshModelBeforeResult(boolean val) { this.refreshModelBeforeResult = val; } @Override public String intercept(ActionInvocation invocation) throws Exception { Object action = invocation

SSH框架中不为人知的细节(二)

隐身守侯 提交于 2019-11-30 07:50:05
Struts2之ValueStack 上一节在将阐述ModelDriven的机制时,常常提到一个名词ValueStack。也许你会毫不犹豫脱口而出,不就是值栈吗?对,就是它,那你知道Struts为什么需要引入它?它是如何工作的?它和OGNL有何私情?如果你对以上问题的答案很模糊,但是又确实想知道答案,那么本文将带你去看看ValueStack的世界。 Why ValueStack? 说Struts就不得不提MVC,所有的请求都是基于页面(View)提交,页面是数据最初的载体,然后提交给Controller,由Controller将数据做第一次处理,然后交给业务层做进一步的处理。下面,我们还是通过代码直观的体会一下。 JSP页面伪码: <form action="xxx/user-add.action" method="post"> username:<input type="text" name="username" /> age:<input type="text" name="age" /> groupName:<input type="text" name="group.name" /> <input type="submit" name="submit" value="添加" /> </form> VO伪码: public class UserVO { private

Struts2 handle multiple actions in single form

我是研究僧i 提交于 2019-11-30 07:36:15
问题 I have a form contains three buttons print / export / save . <s:form action="/userAction"> <s:submit type="image" value="%{'print'}" src="/print.png" /> <s:submit type="image" value="%{'export'}" src="/export.png" /> <s:submit type="image" value="%{'save'}" src="/save.png" /> </s:form> How can I map this in struts.xml ? 回答1: In the struts.xml the action is mapped via the <action tag <action name="userAction" class="... the submit buttons should include method attribute to call corresponding

Struts2 accessing enum from JSP

寵の児 提交于 2019-11-30 05:07:16
I have the following class package com.test; public class SomeClass { public enum COLOR {RED,BLUE} } I want to access values of COLOR enum in my JSP. I've tried the following code but it doesn't work. <s:property value="@com.test.SomeClass.COLOR@RED"/> <s:property value="@com.test.SomeClass@COLOR.RED"/> Any body came across this issue before? [I've already enabled static method access in struts.xml] For enum -s there is not need to enable static method access . Enum-s can be accessed using @ sign like that: <s:property value="@package.ENUM@enumvalue"/> In your case since you are declaring enum

OGNL and wildcards working in tiles definitions with struts2-tiles-plugin?

元气小坏坏 提交于 2019-11-29 17:40:00
I want Tiles to resolve ognl from the struts2 value stack. How to do this? Using tiles 2.2.2 (although if a later version such as 3 could be used that is fine) Here it mentions the new feature: http://tiles.apache.org/2.2/framework/whats-new.html Here it shows how to implement it: http://tiles.apache.org/2.2/framework/tutorial/advanced/el-support.html#OGNL_Support But I'm not certain how to go about that in my project. Does anyone have tiles3 working in their struts2 project? I remember reading about some way to turn on all new features in tiles 3 by default but I can't find a link to that

Struts2 redirecting to another action with unknown amount of parameters

跟風遠走 提交于 2019-11-29 15:47:23
问题 I have a login action which after succesful execution redirects to the previous page (I store the previous page in my session so I can fetch it later). In Struts2, I can find two ways to do this redirection: <action name="login" class="com.myapp.login.Login"> <result name="redirect" type="redirect">${previousAction.requestURL}</result> </action> In this example, the getPreviousAction().getRequestURL() method (this is a selfmade method, its not ntive to struts2) will be invoked and this will

SSH框架之Struts2第三篇

元气小坏坏 提交于 2019-11-29 13:56:51
1.3相关知识点 : 1.3.1 OGNL的表达式 : 1.3.1.1 什么是OGNL OGNL是Object-Graph Navigation Language的编写,它是一种功能强大的表达式语言,通过它简单一致的表达式语法,可以存取对象的 任意属性,调用对象的方法,遍历整个对象的结构图,实现字段类型转化等功能.它使用相同的表达式去存取对象的属性. OGNL : 对象导航语言,是一门功能强大的表达式语言(功能比EL强大很多倍).Struts2将OGNL引入到自身,作为Struts2的表达式语言. struts2的默认表达式语言就是 : ognl 1.3.1.2 OGNL的作用 : 1 : 获取对象的方法; 2 : 获取类的静态属性; 3 : 获取类的静态方法; ognl快速入门 : <!-- ognl简单使用 --> <!-- 1 获取对象的方法(了解)--> 字符串hello的长度是: <s:property value="'hello'.length()"/><br/> <!-- 2 获取类的静态属性(了解) 要求:@类的全限定名@静态属性 --> π的值是:<s:property value="@java.lang.Math@PI"/><br/> <!-- 3 获取类的静态方法(了解) 要求: 1 @类的全限定名@静态方法 2 需要开启允许获取类的静态方法-->

Displaytag struts 2 go to specific page

邮差的信 提交于 2019-11-29 12:45:50
in my project i'm using display tag. The problem comes when the results returned are like e.g. 300 pages. The user needs to jump to page e.g. 200 but he can't. He needs to go slowly there ( 5 pages at a time or so ). I want to add the ability to the user to choose in a drop-down the page he wants to jump to. Is there any property in display-tag or any suggestion? Andrea Ligios You need to use ParamEncoder to get the name (and eventually the value ) of displayTag 's parameters, specified in TableTagParameters.html , in your case PARAMETER_PAGE . <div> With Scriptlets <br/> <% String

After having updated struts2 from 2.3.16 to 2.3.32(fix the S2-045), the JSP file can not resolve some Objects' fields

随声附和 提交于 2019-11-29 12:45:33
Recently we fixed the struts2's 'S2-045' problem.I updated all the struts2 related jar files including freemarker , ognl , xWork ,etc. I use tomcat8 to deploy my dynamic web project. There were not any Exceptions while starting the tomcat-server. But some problems seemed occur: some values(got from db) should be displayed on the jsp pages dose not show up any more . There is no Exceptions thrown. I also can watch that I have already got the very Objects correctly in the Action Classes . the following is some examples // index.jsp ----- here is the list I want to show on the page. // the list

Struts 2 refactoring code to avoid OGNL static method access

大兔子大兔子 提交于 2019-11-29 11:56:29
Struts 2, 2.3.20 mentioned that Support for accessing static methods from expression will be disabled soon, please consider re-factoring your application to avoid further problems! We have used OGNL static calls in validators: @ExpressionValidator( expression = "@foo.bar@isValidAmount(amount)", key = "validate.amount.is.not.valid"), Also we used it in tags <s:set var="test" value="@foo.bar@sampleMethod(#attr.sampleObject.property1)" /> Well, what is the best way to refactor above two usages ?! In your code you are using a static method call. The best way is to create a method in the action