1

I'm trying to access a static member value in JSP as follows: "@package.subPackage.ClassName@STATIC_MEMBER"

STATIC_MEMBER is declared as public static final String with a value assigned and class has public scope. My struts.properties (placed under webapps\appName\WEB-INF\classes folder) has struts.ognl.allowStaticMethodAccess=true entry. But, Struts seems to ignore struts.ognl.allowStaticMethodAccess=true entry in struts.properties.

I had followed same above steps in another project and it's working perfectly fine.

Notes:
1. I had cross-checked full package, class and STATIC_MEMBER name for correctness.
2. There are no errors / exceptions on page.
3. Same JSP is able to access member value from Action class (<s:property value="actionMember"/>).
4. I tried accessing static members from other class but, does not work.
5. I had tried deleting struts.properties file and making an entry in struts.xml file, after <struts> tag, as : <constant name="struts.struts.ognl.allowStaticMethodAccess" value="true" />. Did a re-start and re-tried. But, does not work.
6. I had re-build, re-deployed and re-started server after deleting web app and it's cache (work folder) from server but, didn't work.

Environment: Java 1.6, Struts 2.1, Tomcat 6.0 @ Windows XP 2002

Please help.
Thanks much in advance!

--------------------CODE UPDATE-------------------------------

CLASS

package package1.subPackage1;

public class FooClassName {
   public static final int INVALID_LOGIN = 0;   
}


struts.properties
struts.ognl.allowStaticMethodAccess=true

JSP
<s:if test="errorType == @package1.subPackage1.FooClassName@INVALID_LOGIN"> some code here </s:if>


Action class:
1. private int errorType;
2. has respective getter and setter for errorType

It's not even printing the value, tried:
<s:property value="@package1.subPackage1.FooClassName@INVALID_LOGIN"/>

Quaternion
  • 10,380
  • 6
  • 51
  • 102
lupchiazoem
  • 8,026
  • 6
  • 36
  • 42
  • 1
    Try this , If it's working then there might problem with your class. – MohanaRao SV Apr 13 '12 at 17:38
  • I'd stick with using the constant tag in struts.xml – Quaternion Apr 13 '12 at 22:19
  • @Mohan, thanks for the note. I did try accessing Java in-built static members before posting(missed to mention in above notes list) and it works fine. Accessing static members seems to be problem within my code. But, as I had mentioned in #4 point, I tried accessing static members from class in different package. But, it still does not work. – lupchiazoem Apr 14 '12 at 13:35
  • @Sannidhi post your class and how you are accessing it. – MohanaRao SV Apr 14 '12 at 13:56
  • Sorry can't do that for confidentiality reasons. That's why I had to use example. Otherwise, I understand posting etiquette. Nonetheless, it's so strange. I had accessed many, many times earlier without any problem. Wonder what's going wrong this time... – lupchiazoem Apr 14 '12 at 16:44
  • I'm asking original code, http://sscce.org/ – MohanaRao SV Apr 14 '12 at 17:16
  • Thanks again for being on it. Updated OP with code. – lupchiazoem Apr 14 '12 at 18:23
  • @Inject(value="allowStaticMethodAccess", required=false) public void setAllowStaticMethodAccess(String allowStaticMethodAccess) { this.allowStaticMethodAccess = "true".equalsIgnoreCase(allowStaticMethodAccess); } Attach struts2 source find the above method in class ValueStackFactory and identify whether it's injecting proper value or not. – MohanaRao SV Apr 15 '12 at 16:00

0 Answers0