1. 程式人生 > >Eclipse 內部啟動 Tomcat,瀏覽器訪問出錯的解決方法

Eclipse 內部啟動 Tomcat,瀏覽器訪問出錯的解決方法

在Eclipse裡面配置好Tomcat伺服器後,start server成功後,在瀏覽器輸入http://localhost:8080/, 出現404錯誤,無法看到正常的tomcat頁面。主要原因是eclipse裡面的tomcat server配置問題,在server的 overview裡面的server locations,選擇下面的選項:

Use Tomcat installation (takes control of Tomcat installation)

參考資料如下:

If I start my Tomcat server and try to display Tomcat's default page, why do I see a directory listing or 404 error page?

When creating Tomcat servers in WTP, the default is for the Tomcat server to use a separate instance from the Tomcat installation for reasons explained in this question . There is no attempt to serve the standard Web applications found in the installation. Instead, a simple "ROOT" Web application, containing just a minimal web.xml

file, is provided as the default context. The URL "http://localhost:8080/ " tries to display the welcome file at the base of this ROOT context. Since this ROOT context contains no welcome file, the default behavior for Tomcat is to display a directory listing. This is why you will see a directory listing for this URL with Tomcat 4.0, 4.1, and 5.0 servers. Directly listings have been disabled in Tomcat 5.5 and later, so the result is a 404 error page instead. To modify the Tomcat server in WTP to use the same server instance as the installation, see this
question
.

What configuration option determines whether the Tomcat server uses a separate instance or the instance from the Tomcat installation?

In WTP 1.5.x, the Run modules directly from the workspace (do not modify the Tomcat installation) check box of the server editor controls this option. It is found in the General section of the Overview page. If checked, a separate instance is used. If not checked, the instance from the Tomcat installation is used. The default is checked. It is best to change this option immediately after creating the server, or at least while no projects have been added to the server.

In WTP 2.0.x and later, the Server Locations section has been added to the server editor to provide improved control over this configuration issue. Choosing the Use workspace metadata (does not modify Tomcat installation) will use a separate instance and is equivalent to enabling WTP 1.5's Run modules directly... check box. In addition, the Server Path field displays the location of this separate instance relative to your workspace. A separate instance is also created if you choose Use custom location (does not modify Tomcat installation) and specify your desired location in the Server Path field. Choosing Use Tomcat installation (takes control of Tomcat installation) uses the instance from your Tomcat installation and is equivalent to disabling WTP 1.5's Run modules directly... check box.

Note that changes to the settings in the Server Locations section can only occur when there are no projects present on the server. All the settings in the section are disabled if this is not the case. Remove all of the projects and publish the server to enable the settings in this section.