1. Brief description:
After JSP 2.0, you no longer need to drastically define a bunch of tagsupport or bodytagsupport, using JSP Tag files technology to implement powerful page template technology. Here, combining project development, the application of tag files technology is briefly introduced. For detailed tutorials and information, please refer to Java EE Tutorial, which has detailed e-text information.
Http://docs.oracle.com/javaee/5/tutorial/doc/bnama.html
2. Definition Template:/web-inf/tags/subview.tag
- <?xml version= "1.0" encoding= "UTF-8"?>
- <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
- <!--
- <%@ tag language= "java" pageencoding= "UTF-8" iselignored= "false"%>
- <%@ taglib prefix= "tags" tagdir= "/web-inf/tags/"%>
- <%@ attribute name= "id" required= "true"%>
- <%@ attribute name= "title" Required= "false"%>
- <%@ attribute Name= "Headstyle" required= "false" fragment= "true"%>
- <%@ attribute Name= "Headscript" required= "false" fragment= "true"%>
- <%@ attribute name= "Body" required= "false" fragment= "true"%>
- <%@ attribute Name= "Footscript" required= "false" fragment= "true"%>
- -
- <tags:header/>
- <!--custom CSS section--
- <jsp:invoke fragment= "Headstyle"/>
- <!--Custom JS section--
- <jsp:invoke fragment= "Headscript"/>
- <body class= "Pbody" id= "approveapply" >
- <div class= "Mainhd" >
- <p class= "Maintit" >${title}</p>
- </div>
- <div id= "__body__" >
- <!--custom Body--
- <jsp:invoke fragment= "Body"/>
- </div>
- <jsp:invoke fragment= "Footscript"/>
- <div id= "__footer__" >
- <tags:footer version= "${version}"/>
- </div>
- </body>
Copy Code
Where <tags:header> is the head template, <tags:footer> is the bottom template, the small template is then integrated into the large <tags:subView> template
2. Inherit the template, implement the specific page:/view/deploy/approveapply.jsp
- <?xml version= "1.0" encoding= "UTF-8"?>
- <%@ page language= "java" contenttype= "text/html; Charset=utf-8 "pageencoding=" UTF-8 "%>
- <%@ taglib prefix= "tags" tagdir= "/web-inf/tags/"%>
- <%@ taglib prefix= "app" uri= "Http://risecloud.com/app"%>
- <tags:subview id= "approveapply" title= "Audit Request" >
- <jsp:attribute name= "Body" >
- <div id= "Maingrid" ></div>
- </jsp:attribute>
- <jsp:attribute name= "Footscript" >
- <!--overlay page style class--
- <script type= "Text/javascript" src= "${pagecontext.request.contextpath}/js/deploy/approveapplygrid.js?${app: Pageversion ()} "></script>
- <script type= "Text/javascript" src= "${pagecontext.request.contextpath}/js/deploy/approveapplydialog.js?${app: Pageversion ()} "></script>
- <script type= "Text/javascript" >
- <! [cdata[
- $ (function () {
- var Grid = Approveapplygrid.create ({
- Selector: ' #mainGrid ',
- URL:WINDOW.GETCCTXURL ('/deploy/approveapply!listgameapply '),
- Agree:function (ret) {
- Alert (' Agree ')
- },
- Deny:function (ret, rec) {
- Alert (' Agree ')
- }
- });
- });
- ]]>
- </script>
- </jsp:attribute>
- </tags:subView>
Copy Code
which
1. ID, title, body, Footscript, etc. are in the template area of <tabs:subView>, where each one is replaced.
2. ${app:pageversion ()} is a custom JSP EL Function that forces the user's browser to update the cache when a new version is released. Specifically defined as/WEB-INF/APP.TLD,
- <?xml version= "1.0" encoding= "UTF-8"?>
- <taglib xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd" xmlns= "/HTTP/ Java.sun.com/xml/ns/javaee "xmlns:xsi=" Http://www.w3.org/2001/XMLSchema-instance "version=" 2.1 ">
- <tlib-version>1.0</tlib-version>
- <jsp-version>2.1</jsp-version>
- <short-name>app</short-name>
- <uri>http://risecloud.com/app</uri>;
- <display-name>app</display-name>
- <function>
- <name>pageVersion</name>
- <function-class>com.yy.game.risecloud.taglib.RiseCloundFunctionLib</function-class>
- <function-signature>java.lang.string pageversion () </function-signature>
- </function>
- </taglib>
Copy Code
Note that El function must be static
3. Concrete Effect: The red box outside the chart is a template, the red box is the Inheritance Template page implementation, both unified and convenient. Isn't that what you're dreaming of?
Attention:
1. JSP Tag files are placed in the/web-inf/tags/directory by default and are referenced directly using the file name. If other places, you must use the <jsp-config> declaration in Web. Xml!
2. The TLD of the JSP EL functions is placed under/web-inf/by default, and if other places must use <jsp-config> declaration in Web. Xml!
If they are placed in the default location, they will be loaded automatically when the Servlet container is started. No need to configure any more! For specific use, you can refer to Java EE Tutorial
Java uses JSP Tag Files & JSP EL functions to create your own page template