aspose file tools*
The moose likes JSP and the fly likes how prevalent is EL usage Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "how prevalent is EL usage" Watch "how prevalent is EL usage" New topic
Author

how prevalent is EL usage

Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Since JSP2.0 is only recently started being supported by vendors like BEA(through their version 9.0 server), how common is it to use EL in programming the JSP pages???
[ March 01, 2005: Message edited by: Kishore Dandu ]

Kishore
SCJP, blog
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

I can't speak for everyone, but I've been using the EL since it was introduced in JSP 1.2 with JSTL 1.0.

These days under JSP 2.0, all the JSP pages I create are entirely scriptless. No scriplets. No scriplet expressions. No Java. And my life is so much better for it.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Originally posted by Bear Bibeault:
I can't speak for everyone, but I've been using the EL since it was introduced in JSP 1.2 with JSTL 1.0.

These days under JSP 2.0, all the JSP pages I create are entirely scriptless. No scriplets. No scriplet expressions. No Java. And my life is so much better for it.


Are there any major differences in JSP1.2 EL and JSP2.0 EL.

(I sure can investigate with some digging on the net, but I would like expert observations)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

Under JSP 1.2, the EL was not part of the core JSP engine, but could only be used in conjunction with the JSTL 1.0 tags. Under JSP 2.0, the EL is interpreted by the JSP 2.0 engine. This has two major advantages:

1) The EL can be used within template text as a general replacement for scriptlet expressions.

2) The EL can be used within the attributes of custom actions (formerly known as custom tags).

The latter is actually a much bigger deal than it would seem at first glance.

Additionally, there are some additions to the EL expression language itself; the addition of the ? ternary operator, for example.
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
Hi,

What are the benefits of EL? does they increase execution speed the the jsp in question or what? Why are scriptlets so frown upon? In my part of the world scriptlets are still in use!


Maki Jav


Help gets you when you need it!
Kishore Dandu
Ranch Hand

Joined: Jul 10, 2001
Posts: 1934
Originally posted by Maki Jav:
Hi,

What are the benefits of EL? does they increase execution speed the the jsp in question or what? Why are scriptlets so frown upon? In my part of the world scriptlets are still in use!


Maki Jav


EL helps in the readability and maintainability aspect of a JSP. It will help developers to work on the development aspect of a JSP and content helpers(like web content designers) to work on the content aspect of a JSP).
It is sort of similar to JavaScript, that is a added advantage aswell. In my brief exposure, EL + JSTL + custom tags will make very good and maintainable JSP pages.

I am a novice to EL, so some one like Bear can give more insights.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

Kishore has it correctly in that scriptless pages are easier to create and, most of all, maintain. And I think this is the case whether the pages are maintained by design staff, or by developers who are also reponsible for the remainder of the app. The latter is what I find to be the most common case.

Use of the EL will in no way improve performance. In fact, it's likely to add a small amount of time to the page renderring; though I doubt with any observable degradation.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Maki Jav:
Hi,
What are the benefits of EL? does they increase execution speed the the jsp in question or what? Why are scriptlets so frown upon? In my part of the world scriptlets are still in use!
Maki Jav


I'll answer them backwards:
In my part of the world scriptlets are still in use! Maki Jav
In all parts of the world, they're still in use. There is still a place for them; prototyping, small (one developer) sites, vapor-ware, and certain types of in-house applications etc... Having all the power of Java in a script-like environment that can be updated on the fly is a huge benefit in these types of situations.

Why are scriptlets so frown upon?
They're frowned upon because when abused, they lead to completely unstructured, unmanageable, ASP/PHP like code that becomes a nightmare to maintain. When your database code, control flow code, HTML, CSS, and Javascript are all mixed into one file it is impossible for different developers with different skill-sets to work together on a medium or large size project without trampling each other's code. Database developers have to understand the nuances of HTML/CSS, and web programming. Web designers often end up breaking control flow or database code.

Do they increase execution speed in the the jsp?
No, their purpose has nothing to do with performance.

What are the benefits of EL?
Just adding them to a model1 (non-mvc) app will most likely not give you any benefits. As far as I'm concerned, doing so will only exacerbate the problems listed above. On top of needing to know all of the technologies already mentioned, all people working on a project will also have to learn the syntax for EL and/or JSTL.

To understand their potential benefit, you have to have an idea of how server side java, when well used, allows you to carve up a web app into very cleanly separated components. MVC allows you to create java classes that do nothing but deal with database issues, web-pages that any web designer can jump in and work with, and the most well laid out interface there is (servlets) for dealing with the semantics of web programming.

EL and JSTL help to take away that last barrier to an absolute separation of concerns. Many apps have started out with well planned architectures only to gradually degrade into the mess described above (mixed with servlets and beans) due to 'letting the camel get his nose under the tent'. In a pinch, with a deadline looming, or after releasing, one developer resorts to a scriptlet to quickly fix a problem or add a last minute feature (usually having to due with look and feel). The developer looks like a hero because s/he managed to solve a problem quicky without disrupting a running app. The problem, there is never time to go back and factor that bit of code out of the view. Eventually, the number of scriptlets grows and the app becomes brittle and unmaintainable.

EL and JSTL make it easier to set the "no scriptlet" policy in stone. Basic expressions, iterations, and bean access, used to affect the view can now be performed in a simple scripting language from within the JSP WITHOUT needing to resort to scriptlets. This leaves no excuse for resorting to Java scriptlets in the view.



PS:
One of the things that makes Perl so powerfull and cool is the ability to do the same thing in so many different ways. There are synonyms and shortcuts for almost every operator, statement, and command in Perl. This made it easy for people used to sed, awk, bash, tch, and almost every other unix toolset to work with it. This same, great, concept also became it's downfall as a platform for enterprise web apps. It's possible for two Perl developers to write code with such radically different dialects that each would have a real hard time reading each other's code. Coding standards are very difficult to enforce with it.

One concern I have about JSTL, and EL is that the introduction of these new syntaxes will, in many cases, only make JSP projects messier, more unclear, and much more brittle. IOW: the "Perlization" of JSP. I've already seen people in this and other forums ask about EL in scriptlets and vica versa.

With the new tools comes a heightened need for programmer discipline and sructured design in J2EE
[ March 01, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jeroen Wenting
Ranch Hand

Joined: Oct 12, 2000
Posts: 5093
Scriptlets are also still in widespread use in older JSP applications where there is no need (or budget) to replace them with JSTL/EL or where the application is required to run on JSP engines that do not support JSTL/EL.

In the application I'm working on for example there are hundreds of JSPs riddled with scriptlets.
All new ones I create are scriptless (except a single common include all our pages use which does some housekeeping), and I'm slowly coaching the rest of the team towards JSTL as well (they have no experience with it but are interested in learning).
There is still a lot of JSP training that doesn't mention JSTL or EL at all or at best saves it for the last chapter or so as an advanced technology (thus making people steer away from it).


42
Maki Jav
Ranch Hand

Joined: May 09, 2002
Posts: 435
I have used JSTL, MVC pattern and also some scriptlets in a web application and I agree that JSTL help a lot to keep it cleaner. I like the idea of dynamically generating jsp and serving it to the client. Yes this could be one situation where we have to use as much scriptlets as required.

Now, where does use of EL lie? in Jsp I know. If you have a custom tag ie custom action "sum" which sums up two values...

<sum: valOne="1" valTwo="2" />
and you might be getting it from a previous page textfields txtOne and txtTwo
<sum: valOne='<%=request.getParameter("txtOne")>' valTwo='<%=request.getParameter("txtTwo")>'/>

So how will you use EL here?

Is it used for scoped variable only such as

declaration
<%! String myString="I am" %>

display
<%=myString %>

how would you display myString using EL or how would you pass it to some
variable?

like this <%=$(myString)%> <%request.getParameter("userName")%> ?

but what is the difference then between this and the statement below?

<%=myString%> <%request.getParameter("userName")%> ?


I am novice to EL and what I need is some grounding in its use, or it's advantages. No, I will not go for books at present. I need it from the guys who use it.

Thanx

Maki Jav
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
Originally posted by Maki Jav:
Now, where does use of EL lie? in Jsp I know. If you have a custom tag ie custom action "sum" which sums up two values...

<sum: valOne="1" valTwo="2" />
and you might be getting it from a previous page textfields txtOne and txtTwo
<sum: valOne='<%=request.getParameter("txtOne")>' valTwo='<%=request.getParameter("txtTwo")>'/>

So how will you use EL here?


Here in the first one we dont need to use EL. its quite clean, clear and with no scriptlets. But yes we can modify the second using EL i.e.

Note: Corrected after Bear's post.
<sum: valOne="${param.txtOne}" valTwo="${param.txtTwo}"/>

Incase if we have an attribute named "request" and we try to get it like

${request}

then it will return HttpServletRequest object, not that particular object named "request" bound with the request object.

Thus, I hope it would work. May be EL gurus like Bear will guide us through.
[ March 02, 2005: Message edited by: Adeel Ansari ]
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
No. EL handles expressions, literals and additionally works with JSP in XML syntax.

Examples:

<c:set value="whatever" var="myString"/>
<c ut ${myString}/>
[ March 02, 2005: Message edited by: Adeel Ansari ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61209
    
  66

I can't think retriving parameters inside jsp using EL.


${param.name}

how would you display myString using EL


You don't. You cannot access a scriptlet variable using the EL. The EL operates upon scoped variables; that is, attributes placed in the various scopes available to a JSP page (page, request, session and application).

As Ben has pointed out elsewhere: don't mix and match. Either create scriptless pages using the JSTL and EL, or just use scriptlets and scriptlet expressions. I personally think the latter is madness when the former is available, but it's even crazier to mix them all up together.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how prevalent is EL usage