开发者

Replacing EL in JSP with SpEL from Spring 3.0

开发者 https://www.devze.com 2022-12-15 01:57 出处:网络
Tired of old EL in JSP no开发者_JS百科t being able to invoke methods on beans etc. Can I use SpEL from Spring 3.0 in my JSP:s?The upcoming Spring Framework 3.0.1 release adds a new spring:eval JSP t

Tired of old EL in JSP no开发者_JS百科t being able to invoke methods on beans etc.

Can I use SpEL from Spring 3.0 in my JSP:s?


The upcoming Spring Framework 3.0.1 release adds a new spring:eval JSP tag that allows you to evaluate SpEL expressions from JSP pages.

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>

Future versions will add native integration with JSP 2.1 or > engines via a Unified EL adaption layer.


It would be nice, wouldn't it, but no, JSP EL is a function of the JSP compiler. The best you could do would be to write a custom taglib which evaluated contained SpEL expressions, which would be rather clunky.


I use JBoss EL within Tomcat in the manner described by McDowell. I included the jboss-el.jar in WEB-INF/lib for my application and added this snippet to web.xml:

  <!-- jboss el expressions allow method params -->
  <context-param>
    <param-name>com.sun.faces.expressionFactory</param-name>
    <param-value>org.jboss.el.ExpressionFactoryImpl</param-value>
  </context-param>


If an upgrade is possible, you can get method invocation support in the latest JSP EL/Java EE implementations (e.g. Java EE 6 using GlassFish v3). The JUEL (an EL implementation) doc page suggests you can upgrade either by putting the classes into your JRE's ext directory or by putting them in WEB-INF/lib and relying on the SPI mechanism (this depends on your container supporting this). The latest JUEL version supports method invocations.

I don't know enough about the Spring implementation to know how they plug in their EL support.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号