User-defined tags for JSP

Source: Internet
Author: User
Tags tag name tld

    • Create a class that introduces an external Jsp-api.jar package (available in Tomcat under the Lib package), which inherits the class Simpletagsupport
    • Override the Dotag () method.
The Hellotag class under the JSPPROJEC package:
1  Public classHellotag extends simpletagsupport{2 3 @Override4      Public voidDotag () throws Jspexception, IOException {5 6         7JspWriter out= This. Getjspcontext (). Getout ();8          out. Print ("Hello, I'm a custom label .");9     }Ten  One}
    • Define the configuration file, which is placed in the tags package in the WebContent directory with the file name extension. tld.
<taglib xmlns= "Http://"
Xmlns:xsi= "Http://"
xsi:schemalocation= "Http://"
version= "2.1" >


<name>hi</name> /Tag name
<tag-class>jspprojec.hellotag</tag-class> //Custom Label class

    • To use a custom label in a JSP:
1<% @page import="Java.util.arraylist,java.util.arraylist,jspprojec. Student"%>2<%@ page language="Java"Contenttype="text/html; Charset=utf-8"3pageencoding="UTF-8"%>4<%@ taglib prefix= "My" uri= "Tags/my.tld"%>5<! DOCTYPE HTML Public"-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD">678<meta http-equiv="Content-type"Content="text/html; Charset=utf-8">9<title>insert title here</title>Ten One<body> A  - <my:hi/> -  the</body> -


User-defined tags for JSP

Related Article

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: 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.