• Post Reply Bookmark Topic Watch Topic
  • New Topic

EL & Servlet & JSP

 
Mark Henryson
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

I have some question in my mind regd Expression Language.
1.What is use of EL?
2.How EL is more useful than Scriplets?
3.Why we have to use EL than Scriplets?

I know servlet is act as controller and JSP as view. However all the JSP are finally going to convert as Servlet only. When we have to use Servlet and When we have to use JSP
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Mark Henryson]: 1.What is use of EL?
In a well constructed web app, EL gives the JSP developer/webdesigner a simple and clean mechanism for performing view related functionality without needing to resort to scriptlets.

[Mark Henryson]: 2.How EL is more useful than Scriplets?
In an MVC app, it helps to maintain the separation of the view tier from the model and controller tiers. Scriptlets, on the other hand, open the door to putting anything in the JSP. Because they ARE Java, it is necessary
for someone working with the JSPs to understand the the underlying issues with Java ('==' vs equals(), the perils of using instance variables in JSP, etc..). It's also, just plain, cleaner and easier to read.

[Mark Henryson]: 3.Why we have to use EL than Scriplets?
You don't.
You don't have to follow any best practices.
You could put all of your database handling code, your web-flow code, and everything else right into th JSP if you like.
But.. time has shown us that having a clean separation of concerns results in code that is easier to test, maintain, and refactor.

[Mark Henryson]: I know servlet is act as controller and JSP as view. However all the JSP are finally going to convert as Servlet only. When we have to use Servlet and When we have to use JSP
Again, you don't have to.
You could put everything in the JSPs if you wanted to.
Plenty of apps do.
And Again, those apps that do, tend to be harder to maintain and troubleshoot than the ones that are broken up into clean, isolated components.
Sometimes it takes the experience of working with both for the value of MVC to 'click in'.
[ January 28, 2006: Message edited by: Ben Souther ]
 
Saskia de Jong
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Ben all the way.

EL is a simpler and less powerfull language than Java itself. As the name implies, it can be used only for expressions. There are no constructs for control of flow (e.g. loops like for or while) and no assignments in EL.

The reason Sun has explicitely limited the language is to discourage the practice of putting business logic inside views (which JSPs are). I've been working with Java EE for some time now, and no matter how strict the rules are for a certain project, there are always programmers who just don't get the seperation of concern stuff and end up inserting business logic where it doesn't belong.

In EL itself its pretty impossible to express any amount of business logic, so therefore its the recommended thing to use in views. On the other hand, using a combination of JSTL (which does have loops and assigments) and EL you can still put business logic on pages, although its rather awkward. You would think nobody is stupid enough to attempt such a thing, but on the project I'm currently working on I have indeed seen this happen.

Like Ben said (more or less) if you are particularly shortsighted, you may not grasp the benifits of restricting yourself purposely. However once you are to maintain and extend a 400.000 line enterprise application filled to the brim with business logic in views you probably do.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!