Taglib, EL, OGNL

Source: Internet
Author: User

Taglib, EL, OGNL

Read Catalogue

    • 1. Taglib (tag library) tag libraries
    • 2. EL (expression Language) expression
    • 3. OGNL (object-graph Navigation Language) object Map Navigation language

This article is mainly his own javaweb in EL, OGNL, Taglib personal understanding.

Because the above content is based on the concept of JSP, first of all, I have to talk about the JSP in my eyes.

She is free and unrestrained, like the vast sea, spanning any server barrier, 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 .... Customize the various labels for anyone.

The basic idea of Web view layer has been elaborated by JSP, but it field people don't like the old man who is active in sunshine.

Now a variety of template engine with its flexible form of expression and concise way of writing to suppress the momentum of JSP.

Back to top of 1. Taglib (tag library) tag libraries

JSP native Java code, always give people a messy feeling, and the entire JSP page does not tune.

and increase maintenance difficulty and cost, front-end JSP artwork also must be programmer, increase program development cost.

Taglib is born in this premise, and has been adopted and extended by many javaweb MVC frameworks long ago, to carry forward the vast majority.

The small and lively Taglib the messy native Java code out of the JSP world, restoring the original JSP clean and clean look.

Taglib instance code was 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>      <tr>          <td> name </td>          <td><%=user.getname ()%></td>      </tr>      <tr>          <td> age </td>          <td><%=user.getage ()%></td>      </tr >  </table>  

Introducing struts <c:/> tags 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>      <tr>          <td> name </td>          < Td><c:out value= "${user.name}"/></td>      </tr>      <tr>          <td> Age </td>          <td><c:out value= "${user.age}"/></td>      </tr>  </table>  

May be the business logic is not complex enough, so you may not have a face beard uncle, into the sunny and lively small fresh meat feeling, it doesn't matter, listen to my slow way.

Here are some of the more mainstream TagLib, and specific references:

JSTL (JSP standard Tag Library) developed and maintained by Apache, specific 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=ejr9gefzumw9nw3asq6oustmxaukf018qdv7

Of course you can also customize the extension taglib:http://www.cnblogs.com/edwardlauxh/category/277227.html

Back to top of 2. EL (expression Language) expression

EL design is inspired by the ECMAScript and XPath expression languages, which provide a way to simplify expressions in JSPs.

The EL looks for values from the Web Page, Request, Session, application range, and also from the implicit objects defined Pagescope, Requestscope, Sessionscope, and Applicationscope Gets the data.

EL is not a programming language, is not a scripting language, the best partner for JSTL, can use simple and convenient symbols to express and manipulate complex behavior.

Example of rendering data code in EL and Jstl,java native code HTML is not introduced:

<%       for (user user:userlist) {%>        

Introduce EL and JSTL code examples:

<c:foreach var= "user" items= "${userlist}" >    

${userlist} for El value,<c:foreach> <c:out> for JSTL Loop and output label, is the code after the introduction of El and JSTL simple and understandable?

As for the use and writing rules of EL and JSTL, reference materials:

El:http://www.jb51.net/article/20042.htm

Jstl:http://www.runoob.com/jsp/jsp-jstl.html

It doesn't make sense to list these things, so search for specific items and specific business rules.

Back to top of 3. OGNL (object-graph Navigation Language) object Map Navigation language

OGNL is an upgraded version of EL, the best partner for Struts <s:/> and webwork <ww:/> frame tag libraries.

OGNL provides a number of advanced and required features, such as powerful type conversion capabilities, execution of static or instance methods, cross-collection projection, and dynamic lambda expression definitions.

OGNL's calculations revolve around the OGNL context and can be in a property-driven framework such as struts, webwork. Add, delete, change, and check data in the value stack.

Introducing OGNL and Struts <s:/> Tag Library page rendering code examples:

<s:iterator var= "user" value= "${userlist}" id= "User" status= "status" >    

#status. Index for OGNL value,<s:property/> <s:iterator/> struts tag library output and traverse notes.

The above example is basically a simple routine example, but the actual business logic is always accompanied by changes and complex rules, OGNl basically can meet your requirements.

OGNL specific use and writing rules are not listed, better reference:

OGNL in Struts2: http://blog.csdn.net/tjcyjd/article/details/6850203

WebWork Learning Road "02" Front End OGNL test: http://www.cnblogs.com/java-class/p/5016578.html

Taglib, EL, OGNL

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.