Search code examples
struts2elognl

Advantages of OGNL usage over typical EL in Struts2


Say that I don't leverage OGNL to create my Struts2 web application and just purely uses typical el provided by Sun. What would be the downside of it?

As far as I know, OGNL is a kind of expression which attempts to match the best matched value from ValueStack based on its current state. Could it also be achieved by just using EL alone instead?

Thanks in advance for the responses

Daniel


Solution

  • Short Answer: Yes, you can use the JSP EL instead of OGNL. Both languages have their pros and cons, but there is no looming downside to using either.

    Long Answer: OGNL is used internally by XWork and Struts2, so you can't actually remove the dependency itself, however you can certainly use the JSP EL predominantly (or even exclusively) in your JSP view layer.

    There are pros and cons to using either expression language. One area that OGNL shines over the JSP EL is in dynamic creation of maps and collections, such as for backing <select/> elements, etc.

    However, in most cases I find that the JSP EL is a better fit for me since I make heavy use of JSP simple tags (.tag files).

    @Amit Sharma: I have to disagree that using JSP/JSTL over OGNL and the Struts tags defeats the purpose of using Struts2. The interceptor framework, type conversion, and result types are among the most extensible and compelling reasons to use Struts2. None of those things are tied to any specific view technology.