# CustomTags.jsp Sample

This topic inludes the source code for the CustomTags.jsp Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/tagSamples/custom_tags/

## Sample Source Code

`01 <%@ page language="java" contentType="text/html;charset=UTF-8"%> 02 03 <%@taglib prefix="custom" uri="/WEB-INF/lib/customtags.jar"%> 04 <%@taglib prefix="netui" uri="netui-tags-html.tld"%> 05 06 07 <%-- 08 The following samples demonstrates the use of custom tags in JSP pages. 09 10 To create a custom tag, follow these steps: 11 12 (1) Create a tag handler class file. This file stores the methods executed 13 by the JSP engine whenever it encounters a custom tag on a JSP page. The 14 tag handler class file must import javax.servlet.jsp and 15 javax.servlet.jsp.tagext packages, and it must include a doStartTag method. 16 (2) Create a tag library descriptor (TLD) file. This file will tell the web 17 server where to find the tag handler class when it encounters a custom 18 tag on a JSP page. The TLD file is saved with a .tld extension, but its 19 contents are XML. 20 (3) Configure the application's web.xml file. 21 22 For details see the help topic Creating Custom Tags. 23 24 The sample below uses three custom tags: <custom:simpleHello />, 25 <custom:greeting />, and <custom:textBox /> 26 27 <custom:simpleHello /> displays the text greeting "Hello World". 28 29 <custom:greeting /> does goes one step further, allowing you to greet 30 a user by name. 31 32 <custom:textBox /> shows how you can use custom tags to encapsulate 33 and re-use common page elements. In this case the custom tag renders 34 a text box with a title region and a body region. 35 --%> 36 37 <html> 38 <head> 39 <netui:base/> 40 </head> 41 <body> 42 <jsp:include page="/resources/jsp/header.jsp"/> 43 <h3>Custom Tags Samples</h3> 44 <blockquote> 45 <p>The JAVA source files for these custom tags can be found at <code>SamplesApp/WebApp/WEB-INF/src/tag_handlers/</code> 46 <p><b>Output from &lt;custom:simpleHello />:</b> 47 <p><custom:simpleHello /> 48 <p><hr> 49 <p><b>Output from &lt;custom:greeting name="John Doe" />:</b> 50 <p><custom:greeting name="John Doe" /> 51 <p><hr> 52 <p><b>Output from &lt;custom:textBox title="Sample title text">Sample body text&lt;/custom:textBox>:</b> 53 <p><custom:textBox title="Sample title text">Sample body text</custom:textBox> 54 </blockquote> 55 <hr> 56 <netui:anchor href="/WebApp/tagSamples/tagSamplesController.jpf">Return to Tag Samples</netui:anchor> 57 58 59 60 61 </body> 62 </html>`