Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Powerful browser detection and custom JSP tags with Geronimo

Use Geronimo and Jetty to create a browser and OS detection scheme

Daniel Wintschel (daniel@humandoing.net), Author and developer, 自由职业者
Daniel Wintschel is a regular guy who derives great excitement from solving business problems, streamlining processes, and writing all sorts of Java code. He loves coffee and is currently seeking development opportunities on a telecommuting basis from Singapore. If you are bored one day, you can read more about him.

Summary:  Learn how to take advantage of Apache Geronimo and Jetty to create a powerful browser and open source detection scheme. In addition to the open source (OS) Geronimo application server, this tutorial shows you how to use freely available JavaScript programs to perform browser and OS detection on the client side.

Date:  13 Sep 2005
Level:  Intermediate PDF:  A4 and Letter (341 KB | 26 pages)Get Adobe® Reader®

Activity:  4929 views
Comments:  

Before you start

This tutorial is for developers who would like to implement some form of a browser detection API into an application. You can take advantage of Geronimo as the Java™ 2 Platform, Enterprise Edition (J2EE) application server (specifically its use of Jetty as a servlet container) as well as some client-side JavaScript. You'll be developing a few separate Java-based components including a servlet filter and two custom JavaServer Pages (JSP) tags. You'll use Apache Ant as a build tool to build the .war file that you'll deploy to Geronimo, so some familiarity with Ant is handy. You should be familiar with the concepts of filters and JSP tag libraries, and feel comfortable reading Java source code.

By the end of this tutorial, you should have an idea of how to develop your own basic servlet filters and JSP tag libraries, and be able to implement a robust browser detection API into a J2EE application with the Apache Geronimo application server.

About this tutorial

The content in this tutorial may beg the question, "Why another browser detection tool?" or "Why not use something like BrowserHawk or one of the other available products on the market?" Sometimes it is better to reinvent the wheel when a product doesn't meet your needs or may not integrate cleanly or easily into your application. In addition, many tools, including BrowserHawk, are proprietary, which is not necessarily a bad thing; however, some developers prefer to use more open tools so they can easily adapt them to their specific needs. Geronimo is an excellent example of this. The Apache Software Foundation wanted to provide a completely open source J2EE application server to fulfill a need it felt was not being met within the Java developer community. Its reasoning was not that there weren't any good J2EE application servers around; it was because Apache wanted to build up an open source, certified J2EE server that could be supported by the Java developer community.

The techniques used in this tutorial are relevant not only to browser and OS detection; the same techniques can be used for the detection of which version of Macromedia Flash a client may have installed or which country they're located in. There are some terrific open source JavaScript programs that provide access to this information, and the same technique we're applying today with browser and OS detection can be applied using these other scripts as well.

This tutorial is structured as follows:

  • Custom JSP tags -- a refresher provides a brief overview or refresher course about what custom JSP tags and tag libraries are and how to develop them.
  • JavaScript for browser detection outlines the reasons behind choosing JavaScript for browser detection and the role it plays within our application.
  • Design strategy gives you an overall understanding of how to design this sample application and of the the final build structure that you'll deploy to Geronimo.
  • Server-side components details all of the server-side Java components and source code within the sample application and ties together how these components interact with each other.
  • JSP components and sample usage details the JSP components used within the application and provides examples of how to use the custom tags developed in this application.
  • Trying it out allows you to compile and build the sample application from source and provides all the commands necessary to deploy the application to Geronimo and test the functionality of the application for yourself.

Prerequisites

This tutorial assumes that you have basic knowledge of the Java Servlet API and the Java programming language. Some knowledge of JavaScript won't hurt either.


System requirements

To run the example code in this tutorial, you need to perform the following steps:

  1. Download and install the following applications:
  2. Make sure that the environment variables outlined in Table 1 are defined in your shell.
    Table 1. Setting the environmental variables
    Variable nameRequired setting
    GERONIMO_HOME Set to the root folder of your Geronimo installation
    ANT_HOME Set to the root folder of your Ant installation
    JAVA_HOME Set to the root folder of your Java installation
    PROJECT_HOME Set to the root folder of your BrowserDetection application
    PATH Ensure that ANT_HOME/bin is in your PATH
  3. Extract the supplied .zip file to your preferred location (this will be the project root). The project is laid out as follows:

    Listing 1. Project layout
                                /BrowserDetect/
                  /conf/   ' contains taglib definition
                  /deploy/ ' created by ANT (will contain WAR file)
                  /src/    ' contains Java source code
                  /web/    ' contains JSP, JavaScript and web.xml
                  /build.xml ' ANT build file
    

If you are eager to compile and run the application, jump to the Trying it out section.

1 of 11 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=133180
TutorialTitle=Powerful browser detection and custom JSP tags with Geronimo
publish-date=09132005
author1-email=daniel@humandoing.net
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.