如何修改Tomcat默认URL?实现带/dev前缀的项目访问路径
/dev Prefix to Your Dynamic Web Project URL in Tomcat Got it, let's sort out this URL path change for your Eclipse Dynamic Web Project. You want to shift from the default http://localhost:8080/magicmonitor/... to http://localhost:8080/dev/magicmonitor/panels.jsp—here are two reliable, straightforward methods to make this happen:
Method 1: Configure Tomcat Context XML (Global Tomcat Setup)
This approach modifies Tomcat's core configuration, so the path change will apply every time you run the server:
- Navigate to your Tomcat installation directory, then go to
conf/Catalina/localhost - Create a new XML file named
dev#magicmonitor.xml(the#character tells Tomcat to map this to a nested path) - Paste the following content into the file, replacing the
docBasevalue with the absolute path to your project's web content folder (e.g.,C:\eclipse-workspace\magicmonitor\WebContenton Windows, or/home/yourname/workspace/magicmonitor/WebContenton Linux/Mac):
<Context docBase="/absolute/path/to/your/magicmonitor/webapp" path="/dev/magicmonitor" reloadable="true"/>
- Save the file and restart your Tomcat server.
Method 2: Adjust Deployment Path in Eclipse
If you prefer to configure this directly within Eclipse (so the setting is tied to your workspace), follow these steps:
- Open the Servers view in Eclipse (if you don't see it, go to
Window > Show View > Servers) - Right-click your Tomcat server instance and select Open to load its configuration
- Switch to the Modules tab, then select your
magicmonitorproject from the list - Click the Edit button, then update the Path field to
/dev/magicmonitor - Click Finish, then restart your Tomcat server to apply the change.
Quick Check After Setup
Once you've applied either method, restart Tomcat and test the new URL: http://localhost:8080/dev/magicmonitor/panels.jsp. If you get a 404 error, double-check:
- The
docBase(in Method 1) points to the correct web content folder of your project - The Path value (in Method 2) is exactly
/dev/magicmonitor - Your project is properly deployed to the Tomcat server (check the
webappsfolder in your Tomcat directory—you should see adev#magicmonitorfolder or the deployed project files)
内容的提问来源于stack exchange,提问作者Sandip Bhot

