简体   繁体   English

Tomcat服务器通过Eclipse运行,但是我的应用程序主页抛出404错误

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

I am trying to build a Web app(Java, SpringMVC, Hibernate) of my own and I am pretty new to developing from scratch. 我正在尝试构建自己的Web应用程序(Java,SpringMVC,Hibernate),并且对从头开始开发还很陌生。 The sample project is done. 示例项目已完成。 Tech specs: Maven, Eclipse Oxygen IDE, Tomcat 9. When I right Click Project -> Run as -> Run on Server i am getting the below error: 技术规格:Maven,Eclipse Oxygen IDE,Tomcat9。当我右键单击“项目”->“运行方式”->“在服务器上运行”时,出现以下错误:

Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 说明:原始服务器找不到目标资源的当前表示,或者不愿意透露该资源的存在。

Same happens when I hit the URL( http://localhost:8080/mavenWebApp/getAllCountries ) explicitly in a browser: 当我在浏览器中显式访问URL( http:// localhost:8080 / mavenWebApp / getAllCountries )时, 也会发生相同的情况:

However, when I hit the Tomcat default page( http://localhost:8080 ) it works ok. 但是,当我点击Tomcat默认页面( http:// localhost:8080 )时,它工作正常。

My Controller class 我的控制器班

@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 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>

I have a countryDetails.jsp in WEB-INF/views/ folder. 我在WEB-INF / views /文件夹中有一个countryDetails.jsp。

My complete web.xml 我完整的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>

I have done the bean configurations in spring-servlet.xml, hence applicationcontext.xml in this case is a empty file that I created for the sake of it. 我已经在spring-servlet.xml中完成了bean的配置,因此在这种情况下,applicationcontext.xml是我为此创建的一个空文件。

Please let me know if you want me to paste any other part of my code. 如果您要我粘贴代码的任何其他部分,请告诉我。 Oh and, server logs are not being updated in the otherwise usual Tomcat-Installation-Folder/logs. 哦,服务器日志不会在其他常规的Tomcat安装文件夹/日志中更新。 I am not sure why. 我不知道为什么。

PS I have tried, switching the server properties -> General -> Workspace Metadata to /Servers/Tomcat v9.0 Server And almost all other solutions provided previously out of which none of the seemed to work. PS我尝试过,将服务器属性->常规->工作区元数据切换到/ Servers / Tomcat v9.0 Server以及以前提供的几乎所有其他解决方案,但这些解决方案似乎都不起作用。

In Eclipse, if the Option "Build automatically" is not set, the servlet may not compile. 在Eclipse中,如果未设置选项“自动构建”,则servlet可能无法编译。 Building the project manually and restarting the server may solve the problem. 手动生成项目并重新启动服务器可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM