Tomcat works but I can't reach http://localhost:8080/

前端 未结 2 673
暖寄归人
暖寄归人 2020-12-28 09:28

When I run Tomcat from the windows tray, it starts and I can\'t reach http://localhost:8080/ Tomcat homepage, but if I run it from Eclipse, it works, my applica

相关标签:
2条回答
  • 2020-12-28 09:49

    Understanding Web Application Structure

    A web application is a collection of web resources, such as JSP pages, HTML pages, servlets, and configuration files, organized into a hierarchy as specified in the Servlet specification. You have two ways in which to organize a web application: packed and unpacked. The packed form is called a web archive (WAR) file, and the unpacked form is a collection of directories stored on the file system. The unpackaged format is convenient for web application developers, as it allows them to replace individual files while the application is being developed and debugged. However, in a deployment environment, it’s often more convenient to provide a single file that can be automatically deployed. This reduces the deployment process to placing the file and setting up system resources. Tomcat can also automatically expand a web application once the server has booted. The automatic expansion of WAR files is configured in the server.xml file as part of the element that configures hosts.

    Web Application Context

    Each web application corresponds to a context component, as discussed in Chapter 1, and you assign a context path to each. The default context is called ROOT and corresponds to the name of the server with no other context information. For example, the ROOT web application on your local machine will correspond to http://localhost:8080. If you’ve configured Domain Name System (DNS) settings for your server, it may also be accessible from a location such as

    Users access other web applications by requesting a context relative to the server. For example, users can access Tomcat’s manager web application with the following URL:

    http://
    localhost:8080/manager.
    

    Applications that you place in the webapps folder are named after the directory they’re in. So, you can access the web application in the tomcat-docs directory with the following: http://localhost:8080/tomcat-docs. Each application on the server is known by its name, and users can access resources according to the remainder of the uniform resource locator (URL) after the web application’s name.

    0 讨论(0)
  • 2020-12-28 10:06

    This maybe normal, according to this thread:

    This is normal.
    To see why, double-click on the Tomcat server in the Servers view. This will open the Tomcat configuration editor. Click on the "Open launch configuration" link in the Overview section. This will open the launch configuration properties dialog. Select the Arguments tab and examine the contents of the VM Arguments field.

    Note that the catalina.home property points to your Tomcat installation, but catalina.base points to a ".metadata\.plugins\org.eclipse.wst.server.core\tmp" directory under your workspace.
    Thus, you are running a separate instance of Tomcat. The "webapps" directory under the ".metadata\...\tmp" directory contains only an "empty" ROOT webapp plus any web projects you have added to the server. This is why you get the 404.

    In the Tomcat configuration editor, you can uncheck the "Run modules directly from the workspace (do not modify the Tomcat installation)" option and catalina.base and catalina.home will both be set to your Tomcat installation.
    Be aware that in this configuration, the Tomcat server in Eclipse "owns" your Tomcat installation.
    Every time you start the Tomcat server from Eclipse, the Tomcat files under the Servers project in your workspace will overwrite the files in your installation.

    It was assumed the most would want to keep their Tomcat installation independent from Eclipse Tomcat server, so the default is to create a separate Tomcat instance.
    With separate instances, you can run the Tomcat installation at the same time as the Eclipse Tomcat server provided you modify one or both of them so that the ports they use do not conflict.

    If you would like the standard Tomcat webapps present while keeping the separate Tomcat instance in Eclipse, switch to the Modules tab in the Tomcat configuration editor and use the "Add External Web Module" button to manually add the desired webapps. Note that this will add a little bit to the startup time for the server.

    Note this is for tomcat versions that use WTP x1.5 (seems to be tomcat 5 or below), in tomcat with WTP(Web tools platform) x2.0 and above you no longer get that option. Instead you need to go into server properties and hit switch location which will then show a proper path. then you go into the server config (double clicking the server opens config) and change the "Server Location" to "use Tomcat instillation" (the middle one).2

    0 讨论(0)
提交回复
热议问题