簡體   English   中英

Eclipse(Mars)+ Apache tomcat 8.0 + Apache CXF 3.1.3上的HTTP狀態404

[英]HTTP Status 404 on Eclipse (Mars) + Apache tomcat 8.0 + Apache CXF 3.1.3

我正在使用Tomcat 8.0,但是嘗試在URL中運行應用程序( http:// localhost:8080 / example1 / services / Calculator )時,總是提示HTTP狀態404。1.我進入Tomcat服務器8.0屬性並進行了更改“ tomcat 8.0v本地服務器 ”的位置。

  1. 我還雙擊了Tomcat服務器 ,並將服務器位置更改為“ Use Tomcat Installation ”。

  2. 我復制了ROOT文件夾並粘貼到我的項目文件夾中(proj folder.metadata.plugins \\ org.eclipse.wst.server.core \\ tmp0)。

但是結果與此處的圖片相同。 HTTP狀態錯誤

看到這一問題我會有所幫助,我將不勝感激。

嘗試更改您的web.xml以包括以下內容

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

url模式中的/將告訴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);  
 }
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM