Reputation: 45
I am developing a Struts 2.3 application. In that application I am calling a static utility method from JSP which takes HttpServletRequest
object as argument and returns a string after processing request. When I tried using JSP scriptlet, method got invoked with proper argument like:
<%
String resultStr = com.testapp.util.Utility.getResult(request);
%>
But when I tried to use the OGNL for the same logic, method got invoked with null request object as argument instead of actual request object like:
<s:set name="resultStr" var="resultStr"
value="@com.testapp.util.Utility@getResult(request)" />
I also tried #request
instead of request
in OGNL but in that case method didn't get invoked.
Upvotes: 2
Views: 1041
Reputation: 1
Put this constant in the configuration file to enable static method access.
<constant name="struts.ognl.allowStaticMethodAccess" value="true" />
Use
<s:set name="resultStr" var="resultStr" value="@com.testapp.util.Utility@getResult()" />
and in the getResult() {
HttpServletRequest request = ServletActionContext.getRequest();
Upvotes: 1