1. TAGS - describe, specify, declare and use in this web app

Mirjana's picture

To define a tag, you need to:

  • Develop a tag handler and helper classes for the tag (we will use 2 tag libraries already developed, one by IBM/Sterling Commerce, i.e. userautho and Apache one i.e. taglibs-xtags). In a table below, you can see where you can find them and load into your project, either in file system or in eclipse.
  • Describe the tag in a tag library descriptor, tld file.
  • Specify tags in web.xml descriptor file
  • Declare the tag in web page where it is used

 

Describe the tag – .tld files in WEB-INF/tld

Descibe the tag in a tag library descriptor file (WEB-INF/tld/userautho.tld).

It is just an example of tld file, for this test web application, you can take userautho.tld and taglibs-xtags.tld from SI installation system and bundle them into your final war file. Paths for the tld files are given in a table below.

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"   "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">

<taglib>

      <tlib-version>1.0</tlib-version>

      <jsp-version>1.2</jsp-version>

      <short-name>security</short-name>

      <uri>http://www.stercomm.com/uix/security</uri>

      <display-name>Security</display-name>

      <description>    This tag library contains functionality specific to the    User Authentication and Authorization   </description>

      <tag>

            <name>autho</name>

            <tag-class>

com.sterlingcommerce.woodstock.uix.taglib.common.security.AuthorizeUserAction

</tag-class>

………

<tag>

            <name>validSession</name>

            <tag-class>com.sterlingcommerce.woodstock.uix.taglib.common.security.ValidateSession</tag-class>

            <body-content>empty</body-content>

            <description>             Performs user session validation        if fails, then attempts to forward to login/error page         </description>

            <attribute>

                  <name>login</name>

                  <required>true</required>

                  <rtexprvalue>true</rtexprvalue>

                  <description>relative page url to which user should be forwarded in case of session being invalid/expired failure</description>

            </attribute>

      </tag>

</taglib>

 

Specify the tag – in web.xml

 

Specify the location of your JSP tag library in your Web application’s WEB-INF/web.xml file. Type the following code between the <web-app> and </web-app> tags:

 ….

<taglib>

      <taglib-uri>http://www.stercomm.com/uix/security</taglib-uri>

      <taglib-location>tld/userautho.tld</taglib-location>

</taglib>

<taglib>

      <taglib-uri>http://jakarta.apache.org/taglibs/xtags-1.0</taglib-uri>

      <taglib-location>tld/taglibs-xtags.tld</taglib-location>

</taglib>

 

Declare the tag – in .jsp page

You declare that a JSP page will use tags defined in a tag library by including a taglib directive in the page before any custom tag is used:


<%@ taglib uri=" http://www.stercomm.com/uix/security" prefix="sec" %>

The uri attribute refers to a URI that uniquely identifies the tag library. This URI can be relative or absolute. If it is relative it must be mapped to an absolute location in the taglib element of a Web application deployment descriptor, the configuration file associated with Web applications developed according to the Java Servlet and JavaServer Pages specifications. The prefix attribute defines the prefix that distinguishes tags provided by a given tag library from those provided by other tag libraries.

 

Usage of tags  – in .jsp page

<sec:validSession login="login.jsp?message=Session expired. Please log in again"/>