Newsletter sign-up
View all newsletters

Sign up for our Enterprise Java Newsletter

Enterprise Java

Use Microsoft's Internet Information Server as a Java servlet engine

Run Java servlets with Microsoft's IIS -- without sacrificing portability

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Did you know that you can run Java Servlets with Microsoft's Internet Information Server (IIS) without any third-party products? All you need is plain old IIS and pure Java. Granted, you do need to use Microsoft's Java SDK for reasons that I will explain in this article, but rest assured that your code will be free of any proprietary extensions and remain completely portable to other servlet engines.

Microsoft's Internet Information Server

But why would you want to do something as silly as running a Java servlet in an environment that wasn't designed for that purpose? First, many of us die-hard Java fanatics are trapped in Microsoft-only shops due to circumstances beyond our control. We all have our Linux boxes tucked away under our desks, running IBM's latest JDK and Apache's latest servlet engine, but it will be a cold day in the underworld before our bosses let us deploy products on such a system. You can certainly find commercial servlet engines that run on Microsoft's platforms, but they can cost big bucks. Try explaining to your boss that you need a few thousand dollars for a new Web server because you're going to scrap the free one that came with the operating system (or use it as a simple pass-through proxy, which is how many offerings currently work). Then, once your boss stops swearing, you can ask yourself if you're just a little too anxious to abandon the Microsoft ship. Microsoft and Sun have had their problems, but that doesn't change the fact that IIS is a respectable piece of software. And now that you know it can run Java servlets, it has become a little more appealing.

The Adapter design pattern

The magic that glues those two technologies together is a simple application of the Adapter design pattern. Quoting from the infamous Gang of Four book, Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides (Resources), the intent of the Adapter pattern is to convert the interface of a class into another interface clients expect. But which classes must you adapt? The answer is the handful of core classes that a Java Servlet uses to interact with its environment -- specifically, the Request, Response, and Session objects. As luck would have it, you don't have to adapt the Cookie class -- the translation is handled in-line by the other adapters.

IIS, or more specifically its Active Server Page (ASP) environment, contains a core group of classes that virtually mirror those of the Java Servlet specification. Actually, I should say the servlets mirror the ASP framework, since IIS shipped long before the servlet specifications were written, but I won't add any more fuel to the Microsoft-versus-Sun fire.

The Request, Response, Session, and Cookie objects exist in both frameworks. The only problem is that the interfaces for those objects are incompatible between environments. That's where the Adapter design pattern comes into play. You have to adapt (or wrap) the IIS versions of the objects to make them look and act like servlet versions.

  • Digg
  • Reddit
  • SlashDot
  • Stumble
  • del.icio.us
  • Technorati
  • dzone
Comments (4)
Login
Forgot your account info?

Microsoft's Java SDK and com.iis classesBy Anonymous on August 15, 2009, 2:26 pmYes, but you can use what exists until now, and make interesting applications that can run both in IIS and JSP engines like Tomcat or WebSphere.

Reply | Read entire comment

Microsoft's Java SDK retiredBy Anonymous on August 10, 2009, 6:27 pmThe MSJVM reached the end of its life as of June 30, 2009. The MSJVM is no longer available for distribution from Microsoft and there will be no enhancements to...

Reply | Read entire comment

Dude ...By Anonymous on June 30, 2009, 11:27 amIm only on page 2 but it seems thats what we are doing. If you wrap a java servlet in asp its now a jsp. If you wanna call it jsp instead of asp then see your iis...

Reply | Read entire comment

Adapter for JSPBy Anonymous on November 13, 2008, 3:12 amThis article is really helpful. But apart from servlets how do run JSP's in IIS? Have you wriiten or thought about another adapter? -Abhijit

Reply | Read entire comment

View all comments

Add comment
Anonymous comments subject to approval. Register here for member benefits.
Have a JavaWorld account? Log in here. Register now for a free account.
Resources