ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button

How to Publish Multiple Websites Using a Single Tomcat Web Application
Pages: 1, 2, 3

Registering A Domain Name

Originally, Knowledge Folders was hosted on a static IP at Indent, Inc. With potential changes to internal IP, I decided to get a proper domain address for Knowledge Folders.



I went to GoDaddy.com on the advice of a friend. I found it had excellent support and its prices seemed very cheap. I registered three domains in the process:

knowledgefolders.org
knowledgefolders.net
knowledgefolders.com

Registering these domains was quite simple at GoDaddy, but setting up the rest took some work. Knowledge Folders was physically hosted with Indent at Peak 10, a hosting facility, on a dedicated Windows server, whereas the domain names were registered at GoDaddy.

Securing The Name Servers and Setting Up IP Address Association

To make the domains work, the first thing I needed to know from Peak 10 was the name servers that would be used to resolve the host names. I needed two name servers. For instance, the name servers for Peak 10 are:

NS1.JAX.PEAK-10.COM
NS1.CLT.PEAK-10.COM

The next step was to tell the Peak 10 staff the domain names I'd registered and the physical IP address the host names should be pointing to. With these changes, I was able to access Knowledge Folders with all of the domain names.

Changes to Knowledge Folders

Thus, I was able to take multiple domain names and point them to the same web app on a given physical IP. So for instance, when I accessed http://www.satyakomatineni.com, I was taken to the home page of Knowledge Folders.

But my intention was to go to the homepage of the account identified by the userid of satya. This required changing two things in Knowledge Folders:

  • index.jsp
  • some new definitions in the properties files

The general idea was to have the index.jsp identify the incoming host name and, provided that there was a way to associate the domain name to an account, the index.jsp would transfer control to the home page of that account.

Example index.jsp and Properties File

The source code of index.jsp that accomplishes this is as follows

<!--
*************************************************************
* Sample code for knowing the Knowledge Folders url:
* Standard aspire libraries
*************************************************************
-->
<%@ page import="com.ai.htmlgen.*" %>
<%@ page import="com.ai.application.utils.*" %>
<%@ page import="com.ai.common.*" %>

<!--
*************************************************************
* html header
*************************************************************
-->
<html><head>
<title>Welcome to Aspire Knowledge Center</title>
<link rel="stylesheet" type="text/css" href="/akc/style/style.css">
<script src="/akc/js/genericedits1.js"></script>

<!--
*************************************************************
* Figure out home page, 
* if not found use the main home page of Knowledge Folders
*************************************************************
-->
<%
   String hostname = request.getServerName();
   String homepageurl = AppObjects.getValue("aspire.multiweb." 
                        + hostname + ".homepageurl",null);
   String targeturl = "";
   if (homepageurl == null)
   {
      targeturl = "/akc/akchome.html";
   }
   else
   {
      //hostuserid exists
      targeturl = homepageurl;
   }
   String debug = request.getParameter("debug");
%>
<script>

<!--
*************************************************************
* gotoHomePage() on load
*************************************************************
-->
function gotoHomePage()
{
   debugAlert("gethost on the client side:" + getHost());
   debugAlert("<%=hostname%>:<%=homepageurl%>");
   var targeturl = "<%=targeturl%>";
   debugAlert(targeturl);
   document.location.replace(targeturl);
   
}
<!--
*************************************************************
* some debugging support
*************************************************************
-->
function debugAlert(message)
{
   var debug = "<%=debug%>";
   if (debug == "true")
   {
      alert(message);
   }
}
</script>
</head>
<!--
*************************************************************
* onload
*************************************************************
-->
<body onload="gotoHomePage()">
</body></html>

Here is the Aspire/J2EE configuration file to support the "domain name to account" translation or mapping:

aspire.multiweb.www.satyakomatineni.com.userid=satya
aspire.multiweb.www.satyakomatineni.com.homepageurl=\
/akc/update?request_name=GotoHomepageURL&ownerUserId=satya

Pages: 1, 2, 3

Next Pagearrow