Chapter 15: Shared Tomcat Hosting Finally, keeping these two entities (static files and Web applications) separate aids in keeping the directory structure clean and more maintainable, as shown in Figure 15-1 . /home/websites/ europa.dom/ callisto.dom/ web/ webapps/ web/ webapps/ Figure 15-1: Sample directory structure for a virtual host environment For the purposes of providing a simple test example, create a sample JSP file named test.jsp, in the document base of the default context Web application of each of these domains. For example, the file /home/websites/europa.dom/webapps/ROOT/test.jspshould contain the following simple code:
<% out.println( Welcome to the Europa.dom web server.
); out.println ( Request sent to = + request.getServerName() + : + request.getServerPort() +
); out.println ( Request received by = + request.getLocalName() + [ + request.getLocalAddr() + ]: + request.getLocalPort() +
); %> Create a similar file as /home/websites/callisto.dom/webapps/ROOT/test.jsp. Remember to change the names for the callisto.domdomain. Note the use of the javax.servlet.ServletRequestmethods in the servlet, namely request .getServerName()and request.getLocalName(). These are for testing the script to ensure that the virtual host settings are correct. The getServerName() method returns the name of the server (or IP address) that the HTTP request was sent to. The getLocalName() method returns the name of the server that actually received the request. In this example, both are the same ( callisto.domand europa.dom respectively), but this need not always be the case. Also, as you will see in the section
For high quality website hosting services please check tomcat web hosting website.