Skip to main content

Migrating WebLogic's JSP TagHandler example to GlassFish

Posted by sekhar on May 20, 2008 at 2:50 AM PDT

As I outlined in href="">Migrate
to GlassFish acitivities , I am migrating samples from different
application servers to GlassFish to illustrate migration to
GlassFish. Here, I selected the WebLogic's "JSP TagHandler" sample to
migrate to GlassFish.

JSP Tag Handler Sample Application

The sample application that I migrated is the JSP Tag Handler
sample from WebLogic 9.2 distribution. The JSP Tag Handler application
is an Address Label Maker that uses JSP custom tags, tag handlers,
virtual directory mapping, split directory development.

The source for the WebLogic sample is in the directory

To try the migrated sample to GlassFish

  • Download and unzip href="">
    . The directory gf_jspTagHandlerEar contains files in an exploded EAR format.

  • asadmin deploydir gf_jspTagHandlerEar
  • Visit http://localhost:8080/jsp_tagHandler/TagHandler.jsp

Deployment: WLS Split Directory -> GF Exploded Directory

The JSP TagHandler example uses a split development directory
structure. In this approach, there are two directories - source and
build and supporting ant scripts and config files. The source and
build directory together contains the file for the J2EE/Java EE
application. GlassFish ,on the other hand, supports deployment of a
Java EE application from a directory that is an exploded format of a
deployable archive. Thus, to deploy on GlassFish, I first generated a
EAR file in exploded format using an ant build target in the build.xml
for the WebLogic sample as follows:

  • cd

  • ant build

  • ant package.exploded.ear

The above will build a jsfTagHandlerEar directory in exploded
format as shown below:

WebLogic: Exploded EAR 
     .... application.xml
     .... weblogic-application.xml
++++ jspTagHandlerWar
     .... ExamplesFooter.jsp
     .... ExamplesHeader.jsp
     .... TagHandler.jsp
     .... wls_examples.css
     ++++ WEB-INF
          .... web.xml
          .... weblogic.xml
          ++++ lib
               .... jstl.jar
               .... standard.jar
          ++++ tags
               .... tagHandler.tag

Next, I repackaged the EAR file to replace WebLogic specific
artifacts with GF artificats by the making the following changes:

  • Removed jstl.jar. jstl.jar is the JavaServer Pages Standard
    Tag Library (JSTL) and is already included in

  • Removed standards.jar. The tags are distributed in
    gf-install/lib/appserv-jstl.jar .

  • Removed WEB-INF/lib since neither jstl.jar nor standard.jar
    are required to be packaged.

  • Removed weblogic-application.xml. It was empty in this example.
  • Replaced weblogic.xml with sun-web.xml. The mapping is
    described below.

Thus, the exploded directory for deployment on GlassFish is as follows:

GlassFish: Exploded EAR 
     .... application.xml
++++ jspTagHandlerWar
     .... ExamplesFooter.jsp
     .... ExamplesHeader.jsp
     .... TagHandler.jsp
     .... wls_examples.css
     ++++ WEB-INF
          .... web.xml
          .... sun-web.xml
          ++++ tags
               .... tagHandler.tag

Then, I deployed the exploded directory gf_jspTagHandlerEar on

  • asadmin deploydir gf_jspTagHandlerEar

weblogic.xml -> sun-web.xml Mapping

The following is how I mapped the weblogic.xml to
sun-web.xml. Additional details are after the mapping.

  <!-- weblogic.xml -->

  <?xml version="1.0" encoding="ISO-8859-1"?>
  <weblogic-web-app xmlns="">
  Use the virtual-directory-mapping element to specify document roots other
  than the default document root of the Web application for certain kinds of
  requests, such as image requests. All images for a set of Web applications
  can be stored in a single location, and need not be copied to the document
  root of each Web application that uses them. For an incoming request, if a
  virtual directory has been specified servlet container will search for the
  requested resource first in the virtual directory and then in the
  Web application's original document root.

  <!-- sun-web.xml -->
  <?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" "">
      <property name="modificationTestInterval" value="1"/>
      <property name="verbose" value="true"/>
    <property name="alternatedocroot_1" value="from=/examples/* dir=C:/bea/weblogic92/samples/server/"/>
    <property name="alternatedocroot_2" value="from=/images/* dir=C:/bea/weblogic92/samples/server/examples/build"/>

Virtual Directory Mapping

The example uses virtual directory mapping to locate the BEA logo
in the example. The GlassFish equivalent for WebLogic's
virtual-directory-mapping is the alternatedocroot property. I also had
to make two more changes to bring up the BEA logo. Of course, I could have replaced it with a
GlassFish logo once I was done :-) but I am trying to show migration
issues here.

URL Pattern

In alternatedocroot_2, I changed the URL pattern from
images/* to /images/*. Withtout the preceeding / , the following
WARNING is generated in the GlassFish server.log file
(i.e. gf-install/domain/domain1/logs/server.log )

    [#|2008-05-15T17:57:49.500-0400|WARNING|sun-appserver9.1|javax.enterprise.system.container.web|_ThreadID=24;_ThreadName=httpWorkerThread-4848-1;images/*;_RequestID=1b29dda8-9133-4863-b0ef-9b7ec44c8576;|WEB0504: URL pattern images/* for alternate docbase is invalid|#]

Relative Path in URL

Another issue I ran into was related to use of a relative
path in ExamplesHeader.jsp. This file contains a reference to SRC
using a relative path as shown in the following fragment.

<!-- weblogic : ExamplesHeader.jsp fragment -->

<!-- TITLE -->
<table border=0 cellspacing="18" cellpadding="0">
    <td valign="top">
      <a HREF=""><IMG SRC="../../../../images/logo_tm_onwt.jpg" alt="BEA Logo" width="161" height="96" border="0"></a>

The relative path used for SRC did not work (the BEA logo won't come up). I changed the SRC reference to images/* .

<!-- GlassFish : ExamplesHeader.jsp fragment -->

<table border=0 cellspacing="18" cellpadding="0">
    <td valign="top">
      <a HREF=""><IMG SRC="images/logo_tm_onwt.jpg" alt="BEA Logo" width="161" height="96" border="0"></a>


The code changes were minimal. I plan to followup up and provide
more details on the migration issues outlined above.

As always, feedback is welcome. For questions and feedback, visit Migrate To GlassFish project and follow the "Discussion Forums" link .

Related Topics >>