JSTL tag library, custom tag, jstl tag library custom

Source: Internet
Author: User
Tags tld

JSTL tag library, custom tag, jstl tag library custom
JSTLcore-> c tag!

Out and setremoveurlifchooseforeach

Used to output arrays and collections!


$ {Str}

Equivalent

For (String str: strs ){
...
}

Attribute:
* Items: Specifies the person to loop. It can be an array or a collection.
* Var: Assign each element in an array or set to the variable specified by var.
Note: there must be no space after items = "$ {list }" // "}"

Loop status

You can use varStatus to create cyclic state variables!

Cyclic state variables have the following attributes:
* Count: Number of cyclic Elements
* Index: subscript of the current loop element
* First: whether it is the first element.
* Last: whether it is the last element.
* Current: current element


Vs. index {Vs. count} Vs. first {Vs. last }$ {vs. current}

==========================================

Fmt Library

It is a formatting Library

Value: Specifies a Date type variable.
Pattern: Specifies the output template! Example: yyyy-MM-dd HH: mm: ss


Retain the second decimal point. It will be rounded! If there are less than two digits, the value is 0!


Retain the second decimal point. It will be rounded! If there are less than two digits, do not fill in!

Custom tag

Tld files are generally placed under the WEB-INF, so that the client can not access!

MyTag1 specifies the name of the current tag
Cn. itcast. tag. MyTag1 specifies the tag processing class of the current tag!
Empty specifies the type of the TAG body. Here we use an empty tag!

<% @ Taglib prefix = "it" uri = "/WEB-INF/tlds/itcast-tag.tld" %>
The tag export library specifies the location of the tld file for the page!

Custom Tag Method 2:
The SimpleTagSupport class implements the SimpleTag interface, which saves all the data transmitted by tomcat and provides the get Method for subclass calls. We only need to override the doTag () method.

Advanced

TAG body content
* Empty: No tag body!
* JSP: jsp2.0 does not support this type anymore! The content of the TAG body can be a java Script, a tag, or an el expression.
* Scriptless: it can only be an EL expression or another tag or string.
* Tagdependent: the TAG body content is not executed, but directly assigned a tag processing class!

The tag is not under the execution tag!

End with SkipPageException in doTag () in the tag processing class!
Tomcat will call the doTag () method of the tag processing class, and then Tomcat will get SkipPageException, which will skip other content on this page!

Tag attributes

Steps:
1. Add attributes to your tag processing class!
Add attributes to the tag processing class. The attribute must have at least one set method! This set method will be executed by tomcat before the doTag () method! The attribute can be used in the doTag.

MVC

It is not unique to java. All B/S-structured projects are using it!

M-model (write your own code)
V-View (jsp)
C-Cotroller controller (Servlet)

JavaWeb layer-3 framework

Web layer-> Web-related content (Servlet, JSP, Servlet-related APIs: request, response, session, ServletContext)
Business Layer-> Business Object (Service), which is part of JavaBean
Data Layer-> operation database (DAO Data Access Object) (all operations on the database cannot jump out of DAO), another part of the Data JavaBean at this layer

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.