Home > Net >  HTTP Status 404 – Not Found in spring-mvc using RequestMapping annotaion
HTTP Status 404 – Not Found in spring-mvc using RequestMapping annotaion

Time:09-17

This is index.jsp file

<html>
<body>
<form action="add">
    <input type="text" name="t1"></br>
    <input type="text" name="t2"></br>
    <input type="submit">
</form>
</body>
</html>

This is todo-servlet.xml

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

    <context:component-scan base-package="com.telusko"></context:component-scan>
    
    <mvc:annotation-driven />
    
    <mvc:annotation-driven enable-matrix-variables="true"/>
    
   

</beans>

web.xml file ->

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>todo</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>todo</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

AddController.java file

package com.telusko;

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

@Controller
public class AddController {
    @RequestMapping("/add")
    public String add() {
        return "display.jsp";
    }

}

The error I am facing

HTTP Status 404 – Not Found


Type Status Report

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


Apache Tomcat/10.0.10

After giving the input the error shows up but the error shows. I have also tried other solutions available on stack overflow but none of them worked.I am using spring mvc 4 and used some youtube videos.

CodePudding user response:

Try by adding "/" in action attribute in html form

<form action="/add">

CodePudding user response:

you have not mention @path on top of class in controller.

  • Related