2015-12-25 101 views
0

我正在使用Tomcat 8.0但是當試圖在URL中運行應用程序(http://localhost:8080/example1/services/Calculator)時,我總是提示HTTP狀態爲404。我去了Tomcat服務器8.0的屬性,並將位置更改爲「tomcat 8.0v本地主機服務器」。Eclipse上的HTTP狀態404(火星)+ Apache tomcat 8.0 + Apache CXF 3.1.3

  • 我也雙擊了Tomcat服務器並改變了服務器的位置,以 「使用Tomcat安裝」。

  • 我複製ROOT文件夾並粘貼到我的項目文件夾(proj folder.metadata.plugins \ org.eclipse.wst.server.core \ tmp0)。

  • 然而結果與圖像中的相同。 HTTP Status error

    我很感謝在這個問題上伸出援助之手。

    回答

    0

    試圖改變你的web.xml文件包括以下

    <servlet-mapping> 
    <servlet-name>YOUR-APP-NAME</servlet-name> 
    <url-pattern>/</url-pattern> 
    </servlet-mapping> 
    

    的/在的url-pattern會告訴Tomcat來尋找任何URL在應用程序的根文件夾(你可以改變你的項目名稱與您的主目錄相匹配)。例如,如果你想訪問你的應用程序http://localhost:8080/Calculator,那麼在Eclipse中將你的項目重命名爲Calculator。

    現在你只需要解析傳給你的servlet的真實URL(在的doGet和doPost方法)

    例如

    public void doGet(HttpServletRequest request, HttpServletResponse 
         response) throws IOException, ServletException { 
    
        String url = request.getRequestURL().toString(); 
        String page = url.substring(url.lastIndexOf("/")); 
    
        if("some_page".equals(page)){ 
        //do something 
        }else if("some_other_page".equals(page)){ 
        //do something else 
        }else{ 
         //open default page 
         getServletContext().getRequestDispatcher("/Home.jsp").forward(request, response); 
    } 
    } 
    
    +0

    感謝您的即時響應dsp_user。我將上面的代碼包含在我的web.xml源文件中,但是它在tomcat的啓動時產生了一個錯誤:「在localhost上啓動tomcat服務器遇到了問題」。而服務器將無法運行。你能否提出另一個請求。謝謝。 –

    +0

    請發佈整個堆棧跟蹤 –

    +0

    我正在運行基於Youtube視頻的添加Web服務;像這樣的代碼; - - - - - - - - - package com.inty.server; import javax.jws.WebService; @WebService(targetNamespace =「http://server.inty.com/」,endpointInterface =「com.inty.server.endpoint1」,portName =「CalculatorClassPort」,serviceName =「CalculatorClassService」) public class CalculatorClass implements endpoint1 (int a,int b) \t { \t \t return a + b; \t} }包含的web.xml文件; –