簡體   English   中英

Tomcat服務器通過Eclipse運行,但是我的應用程序主頁拋出404錯誤

[英]Tomcat server is running through Eclipse, But my app homepage is throwing a 404 error

我正在嘗試構建自己的Web應用程序(Java,SpringMVC,Hibernate),並且對從頭開始開發還很陌生。 示例項目已完成。 技術規格:Maven,Eclipse Oxygen IDE,Tomcat9。當我右鍵單擊“項目”->“運行方式”->“在服務器上運行”時,出現以下錯誤:

說明:原始服務器找不到目標資源的當前表示,或者不願意透露該資源的存在。

當我在瀏覽器中顯式訪問URL( http:// localhost:8080 / mavenWebApp / getAllCountries )時, 也會發生相同的情況:

但是,當我點擊Tomcat默認頁面( http:// localhost:8080 )時,它工作正常。

我的控制器班

@RequestMapping(value="/getAllCountries", method = RequestMethod.GET, headers="Accept=application/json")
public String getCountries(Model model) {
    List listofCountries = countryService.getAllCountries();
    model.addAttribute("Country", new Country());
    model.addAttribute("listOfCountries", listofCountries);
    return "countryDetails";
}

spring-servlet.xml

<beans:bean
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
</beans:bean>

我在WEB-INF / views /文件夾中有一個countryDetails.jsp。

我完整的web.xml

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationcontext.xml</param-value>
    </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <servlet>
     <servlet-name>spring</servlet-name>
     <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
     </servlet-class>
     <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
     <servlet-name>spring</servlet-name>
     <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

我已經在spring-servlet.xml中完成了bean的配置,因此在這種情況下,applicationcontext.xml是我為此創建的一個空文件。

如果您要我粘貼代碼的任何其他部分,請告訴我。 哦,服務器日志不會在其他常規的Tomcat安裝文件夾/日志中更新。 我不知道為什么。

PS我嘗試過,將服務器屬性->常規->工作區元數據切換到/ Servers / Tomcat v9.0 Server以及以前提供的幾乎所有其他解決方案,但這些解決方案似乎都不起作用。

在Eclipse中,如果未設置選項“自動構建”,則servlet可能無法編譯。 手動生成項目並重新啟動服務器可以解決問題。

暫無
暫無

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

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