File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Tomcat and the fly likes how to map www.test.com to http://localhost:8080/test/index.jsp on Tomcat server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "how to map www.test.com to http://localhost:8080/test/index.jsp on Tomcat server" Watch "how to map www.test.com to http://localhost:8080/test/index.jsp on Tomcat server" New topic
Author

how to map www.test.com to http://localhost:8080/test/index.jsp on Tomcat server

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
how can i give a url say www.test.com, so that my j2ee app runs on tomcat server.
Is thr any way that i can map such urls instead of user to type http://localhost:8080/test/index.jsp.

thanks in advance


Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Two steps
1) add the mapping 127.0.0.1 www.test.com to you hosts file
2) in your Tomcat context config, add an alias for www.test.com

Once this is done, local requests to www.test.com will be sent to your computer, when Tpmcat sees the request it will look at the HTTP host header (www.test.com) and connect to the correct context.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

A domain name is nothing but an entry in the Internet's "telephone book" that the client's browser users to find the server's IP address. The "hosts" file is a local telephone book, so it can be used to lookup IP addresses for the machine on which it resides, but for the internet at large, the usual procedure is to use a Domain Name Server. DNS provides a more general database of domain names and addresses and it normally chained to upstream domain name servers which form a network that's headed by about 13 global DNS systems.

You'd register a domain name by purchasing the rights to it from a domain name registrar such as Verisign or GoDaddy.

Getting the "8080" off the URL is harder. DNS only resolves IP addresses, not port numbers. When a web browser makes a request to a server, if there's no port number in the URL and the selected protocol is "http", the port addressed will be port 80. For "https", it's 443. That means your Tomcat server must be accessible via those port numbers.

There are 2 ways to do that. One is to change the port settings in the Tomcat server.xml file. If Tomcat is the only webserver on that machine, it's the simplest way. Production machines often offer more than just J2EE services, so there's often a general-purpose server such as the Apache http server installed as well. For that case, a connector links the port 80 requests which go to Apache to the Tomcat server. By default the connection is made by Apache to Tomcat's port 8009.

There are 2 lesser-used options as well. One is to use a proxy server such as Squid. Basically, the proxy server is doing a scaled-down version of what Apache does. The other way, on Linux systems is to use the port translation feature of netfilter/iptables. Although netfilter is most commonly used as a firewall, it can also translate port and/or IP addresses so that you can leave Tomcat on port 8080, but the netfilter will route traffic targeting port 80 to it. I use a variation of this technique to allow my virtual machines to have public addressability.


Customer surveys are for companies who didn't pay proper attention to begin with.
Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
please i didn't understand by
Tomcat context config

where it is exactly?
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

Vinod Vijay wrote:please i didn't understand by
Tomcat context config

where it is exactly?


The Tomcat context config is a file containing a Tomcat Context element definition. It can be located in the WAR's "META-INF/context.xml" file, in the TOMCAT_HOME/webapps directort or in the TOMCAT_HOME/conf/Catalina/localhost directory. Or embedded into server.xml (but please don't!).

However that just defines what webapp a request made to the Tomcat server will be routed to, so I'm not quite sure how it applies to the idea of simplifying the URL domain/port components.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to map www.test.com to http://localhost:8080/test/index.jsp on Tomcat server