Current wisdom in Java web application design says we should abandon Java
scriptlets on JSP pages, in favor of using JSTL/custom actions and embedded
EL expressions. I understand and approve of the reasons for this, but I am
disappointed in the loss of reliability and the reduced performance this
approach produces.

For example, consider a JSP page that, instead of this:

<%= mybean.getCustName( ) %>

contains the following EL:

${mybean.custName}

This results in a performance hit, because every time the page is hit, the
mybean.custName expression must be parsed, a search performed to find the
bean, and reflection used to invoke the getter. Further, reliability is
reduced; if at runtime ${mybean} contains a reference to a bean that does
not have a custName property, an error occurs. To emphasize the reliability
problem, the error does _not_ occur at page translation time (which would be
preferable), but at page execution time. This is especially a problem on
pages that have conditional logic; if an EL expression is only evaluated
under certain conditions, a simple typo can remain undetected for a long
time.

I know that the EL, as a scripting language, is designed to dynamically
discover properties at runtime. However, the flexibility of runtime
introspection is a drawback when it comes to robustness (which I consider to
be more important than performance -- you can always buy faster hardware); I
want to be able to know when I compile the page successfully that no type
errors will occur at runtime. I can envision being able to provide type
hints to the compiler with a <jsp:useBean> action, perhaps like this:

------------------------------------

<jsp:useBean id="mybean" class="beans.MyBean" scope="request" />

${requestScope.mybean.custName}

------------------------------------

Once the JSP engine has been told in advance what type mybean is, it can do
things at translation time like verify that mybean actually does have a
custName property. It could even generate more efficient code, avoiding the
need for runtime introspection. (Right now, all EL expressions seem to be
handed off to PageContextImpl.proprietaryEvaluate( ) for evaluation.)

It seems that better compile-time type checking in the EL would be an
important step to increasing the robustness of web applications developed
with JSP technology. Have there been any proposals along this line? I've
searched the mailing list and looked for a roadmap, without success. Are
there any implementations that do this? Tomcat 5 does not appear to, at
least according to my tests.

I have considered researching adding some experimental implementation of
simple EL type checking to jasper2, but don't want to invest the time and
effort if work is already underway, or if this idea has been considered and
rejected. I would appreciate feedback on this from the community.

Stephen Schaub


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to