jsp2.0+ tag files, JSP fragment technology

Source: Internet
Author: User

Shortly after entering the new company, I used the. tag file in the project today. At first I thought this was a third-party template technology similar to Freemarker. Asked the next project team of other personnel, originally this is jsp2.0 since the JSP fragment technology. It has never been practical to do projects, and it is common to use the Include and Jsp:include methods in JSP. In fact, JSP fragment also has the role of include, but it is more like the third-party Sitemesh technology. For Web page layout and retouching, the ability to separate the contents of a Web page from the structure of a page. So as to achieve the purpose of page structure sharing.

The following examples illustrate how to use JSP fragment.

Official e-Document Http://docs.oracle.com/javaee/5/tutorial/doc/bnama.html

DEMO

1 first in the project's web-inf/tags file, create a new Tpl.tag file such as the following

<%@ tag Language= "java" pageencoding= "UTF-8"%><%@ attribute name= "title"%><%@ attribute Name= "TPL1" fragment= " True "required=" true "%><%@ attribute name=" TPL2 "fragment=" true "required=" true "%><%@ attribute Name=" Tpl3 "fragment=" true "required=" true "%><! DOCTYPE html>

2 Creating a index.jsp file

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%><%@ taglib prefix=" Xjo "tagdir="/web-inf/tags "%><xjo:tpl title=" The JSP tag file uses the content 

3 Interview index.jsp page. Effects such as the following


Detailed description of the label file

The label file must be stored in the Web-inf folder, preferably under the Web-inf folder to create a new tags folder, and then all the label files are stored here. The tag file can use all of the JSP elements, but cannot use the page directive. Tag file multiple one tag instruction

Hidden Object tag files in tag files can use hidden objects: request, Response, Jspcontext, session, application, out, config. The type of Jspcontext implied object is Javax.servlet.jsp.JspContext, which is equivalent to PageContext hidden object of JSP page
The main instructions that can be used in the instruction tag file in the tag file: tag, include, attribute, variable.



The tag command in the tag command tag file is similar to the page directive in the JSP file. The tag file enables you to specify the value of certain properties by using the tag directive to affect the processing and representation of the tag file as a whole. The syntax for the tag instruction is as follows:
<%@ Tag Property 1 = "Property Value" Property 2 = "Property value" ... Property N= "Property value"%>
Multiple tag commands can be used in a tag file, so we often use multiple tag directives to specify the required value for the property:
<%@ Tag Property 1 = "Property value"%>
<%@ Tag Property 2 = "Property
value"%> ...
<%@ Tag Property n= "Property value"%>

<%@ tag language= "java"         pageencoding= "        body-content=" Scriptless|empty|tagdependent        " Deferredsyntaxallowedasliteral= "false"        description= ""        display-name= ""        dynamic-attributes= "        " Example= ""        import= ""        iselignored= "false"        large-icon= ""        small-icon= ""        Trimdirectivewhitespaces= "false"%>

The include directive, like the include designation in the JSP, introduces an external file
<% @include file= ""%>

The attribute instruction is able to dynamically pass the required string data to the tag file by using the attribute instruction in the tag file.
<%@ attribute Name= ""               description= ""               fragment= "false"               required= "false"                rtexprvalue= "true"               type= ""%>
Name indicates the name of the property, and required indicates whether it is necessary, and implicitly feels that False;rtexprvalue indicates whether the property value is sufficient for the run-time expression. As true. Represents a property that can be specified in a dynamic manner. If False, the property value must be specified in a static manner, and the type represents this property, and the default value is Java.lang.string;description, which is used to describe information about this property.
Fragment indicates whether the fragment defaults to False
The variable instruction tag file can be used to return the object in the tag file to the JSP page that called the tag file by using the variable directive
<%@ variable alias= ""              declare= "true"              description= ""             name-from-attribute= ""             name-given= ""              Scope= "nested| at_begin| At_end "%>
Name-given indicates the name of the variable directly specified. Name-from-attribute represents a property value that defines a tag as a variable name; alias declares a local scope property to receive the value of the variable; Variable-class represents the class name of the variable. The default value of Java.lang.string;declare indicates whether this variable declares a default value of True. Scope represents the range of this variable in the range: At_begin, At_end, and nested. The default value is Nested;description, which is used to describe the information about this variable
Jsp:invoke in the label file
<jsp:invoke fragment= ""     var= ""     scope= "page|request|session|application"     varreader= ""/>
Fragment-to the fragment name.
var-gives the variable name, storing the result of the fragment after the JSP container has been computed as a string.
Varreader-ditto, just save the result as a java.io.Reader.
Scope-Scope
To be continued ... ..... .........

jsp2.0+ tag files, JSP fragment technology

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.