Miscellaneous: Taglib, EL, and OGNL; Miscellaneous: taglibelognl
This article is my personal understanding of EL, OGNL, and Taglib in JavaWeb.
Because the above content is Based on JSP, first describe JSP in my eyes.
She is free and unrestrained, just like the vast sea, spanning any server barrier and running on various platforms.
She can accommodate various forms of code and tag libraries, Java native code, JSTL expressions, Struts Taglib, JSF Taglib, Webwork Taglib... various tags customized by anyone.
The basic idea of the Web View layer has been fully elaborated by JSP, but people in the IT field do not like Yang Guan's active elders.
Currently, the wide array of templates engine has a lot of momentum to ban JSP with its flexible expression and concise writing methods.
1. Taglib (tag library) label library
The original java code in JSP always gives a messy feeling, which is different from the whole JSP page.
In addition, it increases the maintenance difficulty and cost. The front-end JSP artist must also be a programmer and increase the program development cost.
Taglib was born on this premise and has been used and extended by many Java Web mvc frameworks a long time ago.
The small and lively Taglib removes the messy native java code from the JSP world and restores the original clean and tidy JSP.
The taglib instance code is not introduced:
<% @ Page import = "cn. javass. user. userModel "%> <% UserModel user = (UserModel) request. getAttribute ("user "); %> <table border = "1"> <tr> <td colspan = "2"> User Information </td> </tr> <td> name </ td> <% = user. getName () %> </td> </tr> <td> age </td> <% = user. getAge () %> </td> </tr> </table>
Introduce the struts <c:/> label and EL expression instance code:
<% @ Taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> <table border = "1"> <tr> <td colspan = "2"> User Information </td> </tr> <td> name </td> <c: out value = "$ {user. name} "/> </td> </tr> <td> age </td> <c: out value =" $ {user. age} "/> </td> </tr> </table>
It may be because the business logic is not complex enough, so you may not have the feeling of an uncle with a full face and a lively little meat. It doesn't matter. Listen to me.
Below are some mainstream TagLib and specific references:
JSTL (JSP Standard Tag Library) developed and maintained by apache, detailed reference: http://www.runoob.com/jsp/jsp-jstl.html
Struts2 Taglib: http://www.blogjava.net/hwpok/archive/2008/10/12/233853.html
Webwork Tablib: http://wenku.baidu.com/link? Url = ejr9gefzumw9nw3asq6ou1_xaukf018qdv7
Of course you can also customize the extension Taglib: http://www.cnblogs.com/edwardlauxh/category/277227.html
2. Expression Language (EL) Expression
EL is inspired by ECMAScript and the XPath expression language. It provides methods to simplify expressions in JSP.
EL searches for values from the Web Page, Request, Session, and Application ranges in turn, and also obtains data from defined implicit objects pagination, requestScope, sessionScope, and applicationScope.
EL is neither a programming language nor a scripting language. The best partner is JSTL. It can use simple and convenient symbols to express and operate complex behaviors.
If EL and JSTL are not introduced, sample code for rendering data in Java native code HTML:
<% For (User user: UserList) {%>
Introduce EL and JSTL code instances:
<C: forEach var = "user" items = "$ {userList}">
$ {UserList} is an EL value. <c: forEach> <c: out> is a JSTL loop and output tag. Is the code after EL and JSTL introduced concise and easy to understand?
For the usage and writing rules of EL and JSTL, refer:
EL: http://www.jb51.net/article/20042.htm
JSTL: http://www.runoob.com/jsp/jsp-jstl.html
It is meaningless to list these items. Search for specific projects and business rules.
3. OGNL (Object-Graph Navigation Language) Object Graphic Language
OGNL is an upgraded version of EL. The best partner is usually struts <s:/> and webwork <ww:/>.
OGNL provides many advanced and necessary features, such as powerful type conversion functions, static or instance method execution, cross-set projection, and dynamic lambda expression definition.
OGNL computing is centered around the OGNL context. You can add, delete, modify, and query data in Attribute-driven frameworks such as struts, webwork, and value stack.
Introduce the OGNL and struts <s:/> tag library page rendering code instance:
<S: iterator var = "user" value = "$ {userList}" id = "user" status = "status">
# Status. index: OGNL value, <s: property/> <s: iterator/> struts tag Library output and traversal notes.
The above example is a simple and regular example, but the actual business logic is always accompanied by changes and complex rules, and the OGNl can basically meet your requirements.
The specific usage and writing rules of OGNL are not listed. Good references:
Detailed description of OGNL in Struts2: http://blog.csdn.net/tjcyjd/article/details/6850203
Webwork learning path [02] Front-end OGNL trial: http://www.cnblogs.com/java-class/p/5016578.html