简体   繁体   English

struts2 2.3.20 ognl allowStaticMethodAccess

[英]struts2 2.3.20 ognl allowStaticMethodAccess

I updated my project to Struts2 version 2.3.20 . 我将我的项目更新为Struts2版本2.3.20。 Now all cases in my JSPs that uses static method access do not work. 现在,我的JSP中使用静态方法访问的所有情况都不起作用。

ie. 即。

<s:set var="linkEscaped"
 value="@org.apache.commons.lang.StringEscapeUtils@escapeHtml(#attr.myObject.link)" />

I already have set in my struts.properties -> 我已经设置了我的struts.properties - >

struts.ognl.allowStaticMethodAccess=true

and tried in struts.xml -> 并尝试在struts.xml - >

<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>

with no success. 没有成功。 Does anyone know what has changed and what do I need to do to enable them again? 有谁知道发生了什么变化,我需要做些什么才能再次启用它们?

Update 更新

Lukasz Lenart commented: Lukasz Lenart评论说:

To be clear, in context of 2.3.20 it's a bug and was temporally fixed, see issues.apache.org/jira/browse/WW-4429 but as from 2.5 access to static methods will be dropped. 需要明确的是,在2.3.20的上下文中,这是一个错误并且暂时得到修复,请参阅issues.apache.org/jira/browse/WW-4429但是从2.5开始访问静态方法将被删除。

--- ---

Allowing static method access was never a preferred way of doing things and in 2.3.20 it won't work even if struts.ognl.allowStaticMethodAccess is set to true . 允许静态方法访问从来不是首选的处理方式,在2.3.20 ,即使struts.ognl.allowStaticMethodAccess设置为true它也不会起作用。

From the wiki : 来自维基

Accessing static methods 访问静态方法

In case you still use static methods in expressions (setting struts.ognl.allowStaticMethodAccess to true ) please be aware that this won't work anymore as internal security mechanism consider this as access to java.lang.Class which is on the excluded list of classes (see above). 如果您仍然在表达式中使用静态方法(将struts.ognl.allowStaticMethodAccess设置为true ),请注意这将不再起作用,因为内部安全机制将此视为对java.lang.Class访问,该列表位于排除的列表中课程(见上文)。 Temporary solution is to copy the above into your struts.xml and remove java.lang.Class from the excluded classes. 临时解决方案是将上面的内容复制到struts.xml并从排除的类中删除java.lang.Class

Support for accessing static methods from expression will be disabled soon, please consider re-factoring your application to avoid further problems! 从表达式访问静态方法的支持将很快被禁用,请考虑重新分解您的应用程序以避免进一步的问题! Please check WW-4348 . 请检查WW-4348

Also WW-4429 . WW-4429

I made it to work. 我让它发挥作用。 Copy the following from the struts-default.xml and copy it into your application's struts.xml. struts-default.xml复制以下内容并将其复制到应用程序的struts.xml中。

<constant name="struts.excludedClasses"
          value="
            java.lang.Object,
            java.lang.Runtime,
            java.lang.System,
            java.lang.Class,
            java.lang.ClassLoader,
            java.lang.Shutdown,
            ognl.OgnlContext,
            ognl.MemberAccess,
            ognl.ClassResolver,
            ognl.TypeConverter,
            com.opensymphony.xwork2.ActionContext" />

Remove only the the java.lang.Class from above. 从上面删除java.lang.Class Save, compile, build, and deploy. 保存,编译,构建和部署。 Happy days! 快乐的时光!

But we are doing an exit strategy for this. 但我们正在为此做出退出策略。 We are making aware all our developers not to use static access anymore and start removing it (We don't have a lot of places this being used though)! 我们已经意识到我们所有的开发人员不再使用静态访问并开始删除它(虽然我们没有很多地方使用它)!

Since static methods will not be able to be used in future releases, I decided to refactor the parts of the project that use them. 由于静态方法将无法在将来的版本中使用,因此我决定重构使用它们的项目部分。 The sooner the better. 越快越好。

So in y "BaseAction" I have created the methods I need and they call those methods. 所以在y“BaseAction”中我创建了我需要的方法,他们称之为方法。 This way only the "safe" methods I allow can be used in the jsp. 这样只有我允许的“安全”方法可以在jsp中使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM