JavaWeb Learning Summary: Configuring Tomcat Server Ports, Virtual Directories, and Host Settings
This tutorial explains how to modify Tomcat's server port, map virtual directories using various methods, configure virtual hosts, register domain names on Windows, and outlines the browser‑server interaction process and the standard structure of a JavaWeb application.
The article is part of a JavaWeb learning series and begins with instructions on changing Tomcat's listening port by editing the Connector element in conf/server.xml. The default port 8080 can be changed to 8081, after which Tomcat must be restarted to apply the new configuration.
Next, the guide describes three ways to map virtual directories in Tomcat. The first method adds a <Context> element with path and docBase attributes inside the <Host> element of server.xml, linking a physical directory (e.g., F:\JavaWebDemoProject) to a virtual path such as /JavaWebApp. Sample XML is provided:
<Host name="localhost" appBase="webapps">
<Context path="/JavaWebApp" docBase="F:\JavaWebDemoProject" />
</Host>The second method relies on Tomcat's automatic mapping of any web application placed in the webapps directory, which creates a virtual directory with the same name as the application folder.
The third method uses a separate XML file (e.g., aa.xml) placed in $CATALINA_BASE/conf/Catalina/localhost. The file contains a <Context docBase="F:\JavaWebDemoProject" /> element; the virtual directory name is derived from the XML file name (e.g., /aa). This approach does not require a server restart when the XML file is added or renamed.
After virtual directory configuration, the article shows how to set up a virtual host by adding a new <Host> element in server.xml, for example:
<Host name="www.gacl.cn" appBase="F:\JavaWebApps">
</Host>To make the host reachable via a domain name, the Windows hosts file ( C:\Windows\System32\drivers\etc\hosts) must be edited to map the desired hostname (e.g., www.gacl.cn) to the server's IP address.
The guide then outlines the complete browser‑to‑server interaction flow when accessing a JSP page, detailing DNS lookup, HTTP request formation ( GET /JavaWebDemo1/1.jsp HTTP/1.1), server processing, and the HTTP response containing the HTML content.
Finally, the article presents the standard structure of a JavaWeb project, emphasizing the importance of the WEB-INF folder and the web.xml deployment descriptor, and provides a minimal web.xml example.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java Captain
Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
