What is the difference between expression language functions and custom tags?

只愿长相守 提交于 2019-12-25 03:23:33

问题


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 ...


来源:https://stackoverflow.com/questions/24721418/what-is-the-difference-between-expression-language-functions-and-custom-tags

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!