Serving JSP pages through IIS using Tomcat

UPDATE – This article was written originally in 2002. The main concept of using Tomcat to handle the JSP pages under-the-hood is still the same and this page is probably still useful, however, there are now products available to do this for you such as JspISAPI (which offers a free lite version). If you want to do it yourself, there is official documentation and another walk-though page here.

The purpose of this document is to provide a walk though for setting up a windows server running IIS to serve JSP pages alongside asp, html, etc. at the moment, this is a fairly complicated procedure. because microsoft does not natively support a competitive technical solution (JSP) and the java community does not necessarily like microsoft that much, there are few resources. this is surprising to me, as it seems a very natural thing to want as a windows server administrator.

although IIS does not support jsp pages, it does have a plugin architecture which they refer to as ISAPI filters. the solution for serving jsp pages through IIS is to actually install a second web server which runs on another port. the second web server we will install is called Tomcat and is provided through the apache foundation. in addition to Tomcat, you install an ISAPI filter that intercepts any .jsp file, forwards it to Tomcat for processing. Tomcat returns the results to IIS, and IIS spits it back out to the visitor. So IIS doesn’t actually processes the jsp page, however from the perspective of the web visitor, that is how it appears.

this document was written for Tomcat version 3 (Tomcat 5 is the current version) and as a result, the content is probably outdated. however, the basics are still very much the same. also we now have the good fortune of a more detailed how-to provided on the apache site which is found here.
http://tomcat.apache.org/connectors-doc/webserver_howto/printer/iis.html. you will probably have the best luck following the instructions on this page.

NOTE: a pre-compiled isapi_redirect.dll can be downloaded from http://tomcat.apache.org/download-connectors.cgi (located under “Tomcat Connectors->Binary Releases”)

——————————————————————————–
Original walk-through:
——————————————————————————–

This How-To provides start to finish instructions for setting up IIS to serve Java Server Pages (JSP). After successfully completing these instructions, IIS will work as normal, except when a JSP is encountered, it will pass it along to Tomcat, which will process and send the results back to IIS. This how-to doesn’t really explain how or why things work, but rather will get you up and running quickly with a configuration that will serve most people’s needs. You should definitely read the Tomcat ReadMe files for more detailed information.

The following file paths will be used in these instructions. If you install to a different directory, then you’ll want to change the instructions accordingly. These seem to be the default installation directories for the programs, except for Tomcat, which doesn’t mention a default installation directory.

Java: C:\JDK1.3
Tomcat: C:\Tomcat
isapi_redirect.dll: C:\Tomcat\bin
IIS Root: C:\InetPub\wwwroot

Part 1: Installing JDK and Tomcat

This first part is just to get the JDK and Tomcat up and running. Tomcat works fine as a stand-alone application, so the most logical place to begin is to get it running properly by itself.

Download (from sun.com) and Install Win32 JDK 1.3 to “C:\JDK1.3″
Download (from jakarta.apache.org) and unzip Win32 binary version of Tomcat (jakarta-tomcat) to “C:\Tomcat”
Right-Click on My Computer -> Properties, go to Evironmental Variables* and set:

TOMCAT_HOME = C:\Tomcat
JAVA_HOME = C:\JDK1.3

IMPORTANT: In the environmental variables, make sure “C:\JDK1.3\bin” is the first directory in your PATH. If you have installed other Java programs, they may try to put their Java Run-Time directory first, which will mess up your Tomcat installation. (It’s also good to keep in mind that if you install another Java application later, it might try to change the path and mess up Tomcat)

* On Win2000, The environmental variables are found on the Computer Properties Advanced tab. If you are on Win95/98, then you probably have to edit autoexec.bat instead.

Restart the computer to finalize changes to PATH
Go to DOS prompt, CD to C:\Tomcat\Bin and start Tomcat by typing “startup” (without the quotes). You should get a 2nd DOS window that is running Tomcat. If the 2nd window flashes and immediately closes, then something is wrong – most likely your PATH (See C:\Tomcat\logs\tomcat.log for info) You can make sure Tomcat is running by opening your browser to http://localhost:8080/ (NOTE: If you have previously installed Sun’s JavaWebServer, make sure it is not running because it also uses port 8080)
Part 2: Installing The ISAPI Redirector and jakarta Virtual Directory

In this part we are installing an ISAPI filter in IIS. What this really means is that when IIS receives a request for pages that meet certain criteria, it will hand it off to another program (Tomcat) to deal with processing, and that program will then return plain text to IIS, which is what IIS will send to the browser. We will also create a virtual directory that allows this to happen.

Download (from jakarta.apache.org) isapi_redirect.dll and copy to “C:\Tomcat\bin”
Download and double-click isapi_redirect_nt.reg or isapi_redirect_2000.reg to import the information into your registry. (If you have used directories other than the one’s specified here, then you should edit the .reg file appropriately before you double-click it). Note: You may have to reboot your PC after the registry update for changes to take effect.
Open IIS management console and create a new virtual directory called “jakarta” and make the physical path “C:\Tomcat\bin” Make sure that this virtual directory has “Execute” permissions.
In the IIS Management Console right-click on your machine name (not the root web) and select properties. Click the Edit button next to the “Master Properties” for the WWW Service. Select the “ISAPI Filters” tab and click “Add” Name the filter “jakarta” and for the executable, browse to C:\Tomcat\bin\isapi_redirect.dll file.
Now go to the control panel, select Services and restart the IIS Admin service (make sure Word Wide Web Publishing Service restarts as well). After you have restarted, go back to the ISAPI filters screen and make sure that the jakarta filter has a green arrow next to it. If it does, then everything is working.
Make sure that Tomcat is running. Open your browser to http://localhost/examples/ – you should see that Tomcat is serving this directory. There are several JSP examples which you can click on to test.
Part 3: Configuring Tomcat to handle JSP files, and IIS to deal with everything else.

This part we are configuring two things – telling Tomcat where the JSP files are going to be found (using server.xml) and telling the ISAPI filter which pages should be redirected to Tomcat (using uriworkermap.properties)

Open C:\Tomcat\conf\Server.xml in notepad and find the line towards the bottom that looks like this:

<Context path=”" docBase=”webapps/ROOT” debug=”0″ reloadable= “true”/>
and change it to this:
<Context path=”/” docBase=”C:/InetPub/wwwroot” debug=”0″ reloadable=”true”/>
(if that line doesn’t already exist, then just add it)
Open C:\Tomcat\conf\uriworkermap.properties with notepad. Add the following line anywhere in the file:

/*.jsp=ajp12

If you like, you can comment out the other lines that redirect the examples and servlet directories, although it doesn’t hurt anything to leave them there.

Make sure that it is working by browsing to http://localhost/ to see that your normal default page is still showing up as expected. Now place a file called test.jsp (or whatever) in C:\InetPub\wwwroot and browse to http://localhost/test.jsp If you put some JSP code in there, it should execute. If you didn’t, then the blank page should load. If you are prompted to download instead, then something is not working.
That is it. The final thing you might want to do is to install Tomcat as a service so you don’t have to open it in a DOS window every time. Instructions for installing the service can be found on jakarta.apache.org – look for “Working with the Jakarta NT Service” or “jk_nt_service.exe”

14 Responses to “Serving JSP pages through IIS using Tomcat”

  1. monali November 15, 2006 at 3:34 pm #

    Hi

    I am trying to set up IIS to serve JSP pages through tomcat. However, I am not able to find the isapi_redirect.dll as mentioned in your mail. Can you please send me the location for where can I find the same.

    Waiting for reply…
    Thank you,
    Monali

  2. Jason November 19, 2006 at 9:28 pm #

    According to this page: http://tomcat.apache.org/connectors-doc/howto/iis.html there is a pre-compiled version in the win32/i386 directory of tomcat-connectors distribution. Good luck! If you find it, be sure to post follow-up here to let others know. Thanks!

  3. a December 7, 2007 at 11:37 am #

    done. however after configuring the connector- I want it to work only from IIS i.e http://localhost/examples should work but http://localhost:8080/examples should not – how do you achieve this.

  4. Jason December 8, 2007 at 3:29 pm #

    to a – well, tomcat is always running and doing the actual work so it does need to be running on *some* port. there’s no way around that. however, you can just block this port from the outside via a firewall or soemthing if you don’t want people hitting 8080 directly. alternatively you could pick a more obscure port to use.

  5. Tim May 14, 2008 at 11:03 am #

    I’m trying to find this file isapi_redirect_nt.reg I haven’t been able to find any trace of it’s existance or were it would come. Based on the way the article is written I was assuming that it was located on the http://www.jakarta.apache.org any information you have would prove usefule

  6. Natasha November 20, 2008 at 7:28 am #

    Hi,

    I have tried this out and it works fine. But doesnt seem to be working..Could it be because of this bridging?

  7. Jason November 24, 2008 at 4:37 pm #

    Hi Tim & Natasha, I wish I could help but I haven’t kept up to speed. If you find any answers, though, please feel free to post a comment. Thanks.

  8. Ayan June 3, 2009 at 12:48 am #

    Problem remains the same. No getting that .dll file from apache website. Please help.

  9. balaji March 15, 2010 at 2:35 am #

    hi friends, i need isapi_redirect.dll . where it is in the sites? tell me please.
    i need it urgently

  10. Jason March 15, 2010 at 1:11 pm #

    isapi_redirect.dll can be downloaded from http://tomcat.apache.org/download-connectors.cgi (located under “Tomcat Connectors->Binary Releases”)

  11. Bret June 15, 2010 at 5:28 pm #

    I have this working but have another issue now with virtual directories.

    I have my docBase set to C:/InetPub/wwwroot and I have a file test.jsp under C:/InetPub/wwwroot/directory1/directory2. I am able to hit http://localhost/directory1/directory2/test.jsp without any issues. I run into issues when I create a virtual directory that points to C:/InetPub/wwwroot/directory1/directory2. I want to be able to hit this jsp through the virtual directory.

    Eg. http://localhost/virtualdirectory/test.jsp

    I get a Tomcat 404 error though. I think this is because Tomcat doesn’t see the virtual directory since it’s part of IIS and not on the filesystem which Tomcat is looking at.

    This does work through virtual directories with IIS and JRun though.

    Any idea how I would get this working with Tomcat?

    • Jason June 16, 2010 at 12:51 pm #

      @Bret The problem is that you mapped a virtual URL to a physical file location within IIS, but you did not tell Tomcat the same information. I’m not exactly sure how to get this to work but I think you should be able to create another “Context” record in conf/Server.xml so that Tomcat will also know the physical location of the files as well.

      Basically in this setup you are fooling Tomcat into thinking it is a normal web server, so it doesn’t have any awareness that it is running via a proxy and it doesn’t have any awareness of IIS settings.

  12. Bret June 17, 2010 at 12:17 pm #

    Thanks Jason. I initially tried adding a bunch of different contexts for each virtual directory but then ran into path issues within the JSP when referencing images and other files since my base path was no longer wwwroot. What I’m doing now is using the Tomcat ISAPI rewrites.properties to rewrite any virtual context to it’s actual context. This seems to do the job. There are still however issues within some of the JSPs that do JSP includes to virtual directories. All of this somehow worked with JRun before. The JRun ISAPI in IIS must have been smart enough to use virtuals in IIS for JRun as well.

    • SUNNY SAHA October 13, 2010 at 9:05 am #

      @Jeson.I’m facing same kind of problem like Bret. In my case i want to host a site which has jsp and asp page under one folder, physically located under iis not under TOMCAT.

      I have one more question: if a put my folder under tomcat and create a virtual folder at iis then can the ASP page be proceed?

Leave a Reply

Please leave these two fields as-is: