Why would I go for custom tags instead of el functions? What are the advantages / disadvantages when they are compared?
问题:
回答1:
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. EL on itself is not very useful!you can use EL with Custom tags to help simplify your code especially for non-java programmers! Have alook on the use of EL in Custom tags here:http://www.java-samples.com/showtutorial.php?tutorialid=551
回答2:
I can also add this information:
JSP tags are implicit to jsp pages. They do not require any dependencies. One example would be
<jsp:useBean ....
Now .tld files, called tag library directories come with more tags. One is JSTL, Java Standart Tag Library. It defines: Java Standart Tags and Function Library.
Eventough function library is defined in a tag library, they are actually not tags, they are expression language functions. They can only be used in EL expressions. JSTL Function Library (usually used with fn namespace) can not be used outside of EL expressions.
Java Standart Tag Library also defines Standart Tags. An example is
<c:out ...