Eclipse & Tomcat Error: HTTP Status 404 – Not Found:

Jawad Tariq

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

This is my HomeController Class:

package com.luv2code.springdemo.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HomeController {

    @RequestMapping("/")
    public String showPage() {
        return "main-menu";
    }
}

This is my Web.xml File:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">

    <display-name>spring-mvc-demo</display-name>

    <!-- Spring MVC Configs -->

    <!-- Step 1: Configure Spring MVC Dispatcher Servlet -->
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring-mvc-demo-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <!-- Step 2: Set up URL mapping for Spring MVC Dispatcher Servlet -->
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

This is spring-mvc-demo-servlet file

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd">

    <!-- Step 3: Add support for component scanning -->
    <context:component-scan base-package="com.luv2code.springdemo" />

    <!-- Step 4: Add support for conversion, formatting and validation support -->
    <mvc:annotation-driven/>

    <!-- Step 5: Define Spring MVC view resolver -->
    <bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/view/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

This is main-menu.jsp file

<!DOCTYPE>
<html>

<body>

<h2>Spring MVC Demo - Home Page</h2>

<hr>

<a href="showForm">Hello World form</a>
</body>

</html>

Here is the Image of Directory

Directory Image in Eclipse

PS: I have tried all other option including switching the location, cleaning the directory and reinstalling tomcat and eclipse but all these are not working for me.Even, I changed the IDE from Eclipse to IntelliJ Idea but problem persists.

Shubh

Since your servlet name is 'dispatcher' Spring looks for the file dispatcher-servlet.xml in the default location of your WEB-INF folder. Try renaming spring-mvc-demo-servlet.xml to dispatcher-servlet.xml and it will work.Hope it helps, Thanks

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to redirect "HTTP Status 404 – Not Found" to an error information page in tomcat?

HTTP Status 404 – Not Found tomcat spring

HTTP Status 404 – Not Found on Tomcat server

JAX-RS Rest service giving "HTTP Status 404 – Not Found" error tomcat while accessing in docker

HTTP Status 404 - on Eclipse with Tomcat (with no generated web.xml)

HTTP Status 404 Not Found For Jersey REST application with Eclipse and Payara server

Eclipse, tomcat, 404 error

Eclipse Tomcat Error 404

HTTP Status 404 Tomcat Apache

HTTP Status 404 - Servlet not found

Servlet: HTTP Status 404 - Not Found

Jersey tomcat and eclipse: error 404

Getting HTTP Status 404 - / error message when hitting URL http://localhost:8080/ in Tomcat?

Apache Tomcat 9 - HTTP Status 404 on browser

tomcat changes 404 status into 403 for http delete

Http Status 404 after installing Tomcat 9

Get HTTP Status 404 - Not Found, when the name of a dynamic web project renamed and deployed on Glassfish with Eclipse

Maven web project HTTP Status [404] – [Not Found]

HTTP 404 status code (Not Found) shown as 302

HTTP Status 404 – Not Found Spring Boot

HTTP Status [404] ? [Not Found] for /login in spring security

JSP/JDBC: HTTP Status 404 - Not Found

HTTP Status 404 - Not Found - Servlet and JSP

JavaEE 8, Tomcat 8.5, Error Status 404

How can I ignore the error of HTTP Status 404 in Tomcat v7.0?

Spring Boot, Status 404, Error "Not Found"

"status": 404, "error": "Not Found", "path": "/GetProduct"

Can someone explain this error for me 'HTTP Status 404 – Not Found Spring MVC'?

when trying to run struts2 with eclipse juno server,getting HTTP Status 404 error