1

I am trying to make simple project in Spring MVC,but getting this error :

WARNING: No mapping found for HTTP request with URI [/SpringMVCForm/login.htm] in DispatcherServlet with name 'springform'

HTTP Status 404 - Not Found.

Not able to get what I am missing. Please let me know.

web.xml:

<?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_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>SpringMVCForm</display-name>
  <welcome-file-list>

    <welcome-file>index.jsp</welcome-file>

  </welcome-file-list>

  <servlet>
    <servlet-name>springform</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springform</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>
</web-app>

springform-servlet.xml :

<?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-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">


<context:component-scan base-package="com.mvcform.*" />

<mvc:annotation-driven />

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/"></property>
    <property name="suffix" value=".jsp"></property>
</bean>

</beans>

LoginController.java

package com.mvcform.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/login.htm")
public class LoginController {

    @RequestMapping(method=RequestMethod.POST)
    public ModelAndView processCredentials(@RequestParam("userId") String userId, @RequestParam("password") String password) {
        String message = "Invalid Credentials";
        if (userId != null && userId.length() >= 5) {
            if (userId.equals(password)) {
                //message = "Welcome " + userId + " !!!";
                return new ModelAndView("redirect:/showform");
            }
        }
        return new ModelAndView("index", "message", message);
    }
}

index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Spring MVC Form</title>
</head>
<body>

<h1> Index.jsp </h1>

<h1>Enter your user id and password</h1>
    <form action="login.htm" method="post">
        <table>
            <tr>
                <td> User Id </td>
                <td> <input type="text" name="userId" /></td>
            </tr>
            <tr>
                <td>Password </td>
                <td> <input type="password" name="password" /></td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Submit" />
                </td>
            </tr>
        </table>
    </form>

</body>
</html>

I think Spring is not able to scan base package: com.mvcform.*

Please let me know what I am missing here.

Aman Saxena
  • 11
  • 1
  • 5

2 Answers2

0

1) if you configured correct then you must check the json format which you sending to server to save it may be wrong (refere the urlenter link description here)

2) please check your controller controller doesn't have this url "URI [/SpringMVCForm/login.htm]" you have only /login.htm url.

iragond
  • 60
  • 6
0

Remove @RequestMapping("/login.htm")

and keep only @RequestMapping("/login")

in controller

prsutar
  • 429
  • 2
  • 4
  • 17