How can I support HTTPS (SSL) in a servlet?

Jim Garrett

The servlet technology by design already supports https (SSL). However, the way this works is not through the servlet technology but through the Web Server. The web server controls whether information is done securely (https) versus non-securely (http).

One way to force servlets to go down the https path is to define your web server to only allow secure connections when accessing servlets. In IIS this can be accomplished through the definition if ISAPI filters. The ISAPI filter can instruct the web server to route all requests that end with a pre-defined prefix to the servlet engine. The trick is to then define files, with the predefined extension, in the web servers directory. For example, if the servlet's name is MyServlet a file with the name would be placed on the web server. All calls to this file would be routed to the servlet engine. And IIS would be used to force all calls to the file to go through https. The JRun servlet engine has examples of how to do this documented on their web page.

About | Sitemap | Contact