Thursday, July 2, 2009

Static method access using OGNL & Struts 2.1.x

We know that if we want to access any static method using OGNL in Struts 2 we use notation @classname@methodname( args ) and it works well. With Struts 2.1.x, by default this has been turned off due to some security issues. You can still access static methods but, you need to tell struts explicitly to allow access to static methods. To do this in you struts.properties put following line…

struts.ognl.allowStaticMethodAccess=true
For more details on this change check Jira WW-2160

I wasted an hour on figuring out why my static method is not called and found this fix with Struts 2.1.x. If you guys are working on 2.1.x then keep this in mind in order to stay away from frustration ;-).

Cheers !!!
- Jay

P.S.: Actually I should have read Struts 2.0.x to Struts 2.1.x migration guide before starting working on Struts 2.1.x
 
Disclaimer : This is a personal blog and all content represent what I think and it does not advocate/support/advertise any other person/company. I do not earn money or intended to do so with this blog or any of the contents the blog hosts (except the google ads which you see). If I post something here that you find helpful, that's wonderful. Just in case, if I say something stupid, the stupidity is mine, and mine alone and I can not be held for anything if you fall for such stupidity :-). I cannot be held responsible for any kind of damage that may be caused by downloading or viewing the files or information provided herewith. Anybody and everybody can use/refer the contents of this blog at their own will and of course at own risk. There is no need for any kind of approval of the author. Although it would be great if feedback is left for any such usage to the author.