Conditional expression in JSP with Struts2 tag

I maintain an old application developed with Struts2.

I updated Struts2 library from 2.3.19 to 2.3.24.

I'm deploying to Tomcat 8 with jdk8.

In a JSP I have this conditions that works fine with old Struts2 library, jdk 7 and Tomcat 7)

<s:if test='%{current.getClass().name == "com.mycompany.myapp.MyCalss1"}'>
  <div>Class1</div>
</s:if>
<s:if test='%{current.getClass().name == "com.mycompany.myapp.MyCalss2"}'>
  <div>Class2</div>
</s:if>

Anything changed from struts 2.3.19 to 2.3.24? or jdk8, Tomcat 8?

When I add <s:property value="%{ficheCourante}"></s:property> to the JSP it shows com.mycompany.myapp.MyCalss2@46e9d4ac.

Answers


Class retrieval (i.e. current.getClass()) in JSP isn't allowed anymore due to security reasons. Create a method in your action class and do the comparison there. In JSP you can call it something like that.

<s:if test="compareCurrentClass('com.mycompany.myapp.MyCalss1')">

Or if you need to pass instance of current to compare method then:

<s:if test="compareCurrentClass(current, 'com.mycompany.myapp.MyCalss1')">

In that case declare compareCurrentClass in your action as:

public boolean compareCurrentClass(Object current, String name)

BTW currently latest S2 version is 2.3.28.


Need Your Help

Automatic dependencies in TeamCity (or other continuous build)?

dependencies continuous-integration teamcity

I'm thinking of implementing a really large continuous build at work (hundreds of Visual Studio solutions, thousands of projects). It includes .NET, C++, and VB6 code. We have some solutions buil...

Flex viewstack children includeIn works funny

apache-flex states viewstack

I have a viewstack with childrens which I want to show/hide depending on the state the application is