Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exact difference and relation between JSTL and Expression Language

Tags:

After reading the Q&A How to avoid Java code in JSP files? I stopped coding with scriptlets.

So started reading JSTL and got a doubt that I found JSTL is have a relation with EL.

But I am not getting the exact relation between them.

Here I got the code from here

 <c:set var="test" value="JSTL Core Tags"></c:set>  <c:out value="${test}"></c:out> 

I know <c:set is a JSP tag and ${test} is Expression language ..

My confusions are

  1. Won't working with JSTL alone work? Does it always need the support of EL ? If not always needed, how in the above case?

  2. How to simply use the Expression language without JSTL tags?

like image 844
Suresh Atta Avatar asked Apr 06 '13 07:04

Suresh Atta


People also ask

What is difference between Scriptlet and expression?

Difference Between Scriptlet Tag and Expression TagThe declared variables have a local scope only and hence can't take access from another place in the . jsp. In contrast, the Expression Tag has the capability to evaluate the Java expression.

What is the difference between JSTL and JSP?

JSP lets you even define your own tags (you must write the code that actually implement the logic of those tags in Java). JSTL is just a standard tag library provided by Sun (well, now Oracle) to carry out common tasks (such as looping, formatting, etc.).

What is the difference between Scriptlets and expressions in Rails templates?

Scriptlets are Ruby code, placed between <% and %> tags. Scriptlets rely on side effects, or the output of the Ruby code. Expressions are Ruby expressions placed between <%= and %> tags. The expression presents the value returned by the Ruby code.

Is JSTL a language?

Computer language used in JSTL for expressing simple expressions, which is based on the XPath and JavaScript or JScript languages. Web pages that use templates, custom elements, scripting languages, and server-side Java objects to return dynamic content to a Web browser in the form of HTML or XML.


1 Answers

The EL, initially, has been designed to be used inside attributes of the JSTL tags, and any other custom tag you might want to use or write yourself.

A later version of the JSP spec has allowed using the EL directly inside the JSPs, but this doesn't mean the JSTL isn't useful anymore. The only thing you can do with EL directly in the JSP is to write some value to the response like for example

${user.id} 

which would write the ID of the user bean. If you want tests, loops, HTML escaping, URLs, date an number formatting, etc., you still need to use the JSTL.

like image 120
JB Nizet Avatar answered Oct 17 '22 10:10

JB Nizet