2017-10-19 85 views
-2

我正在尝试构建自己的Web应用程序(Java,SpringMVC,Hibernate),而且我从头开发很新。 示例项目已完成。技术规格:Maven的是,Eclipse IDE的氧气,Tomcat的9 当我点击右键项目 - >运行方式 - >服务器我得到下面的错误上运行:Tomcat服务器正在运行Eclipse,但我的应用程序主页正在抛出404错误

Description: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

同样的情况,当我打的网址(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 /视图/文件夹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中,在这种情况下,因此applicationContext.xml的是,我对于它的缘故创建一个空文件。

请让我知道如果你想我粘贴我的代码的任何其他部分。 哦,并且服务器日志不会在其他通常的Tomcat-Installation-Folder/logs中更新。我不知道为什么。

P.S.我试过了,将服务器属性 - >常规 - > Workspace元数据切换到/ Servers/Tomcat v9.0服务器 几乎所有其他解决方案都提供了前所未有的功能。

+0

不知道你到底在问什么 – Ravi

+0

我的tomcat服务器已启动并正在运行,并且默认页面也正常加载。但是,当我尝试运行我的项目时,它抛出404错误与描述:原始服务器没有找到目标资源的当前表示或不愿意透露存在。 – Guru

+0

有人请提供一只手吗?这是我的第一个项目,看起来我已经成为了一个死难者。 – Guru

回答

0

在Eclipse中,如果没有设置选项“自动构建”,则该小服务程序可能无法编译。手动构建项目并重新启动服务器可能会解决该问题。

+0

构建自动被打勾。但它似乎并没有解决我的问题。 – Guru

相关问题