0

I am creating a simple login page with model and controller using maven, Spring 3.1.1. I have just created a model and controller. But while running the application I get a 404 error in my browser and in console I am getting the following error:

org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/TEST2/] in DispatcherServlet with name 'dispatcher'

I have checked the configuration properly and I couldn't find the exact error for this.

I have changed some of the configuration. I tried putting /* in URL-Mapping but I am facing the same issue.

My Web.XML

<?xml version="1.0" encoding="ISO-8859-1" ?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
        version="2.4">

        <display-name>Spring MVC Application</display-name>

        <servlet>
            <servlet-name>dispatcher</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>

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

        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
        </context-param>

        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    </web-app>

dispatcher-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" 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">

   <context:component-scan base-package="com.concretepage.controller" />


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

</beans>

LoginController.Java

package com.concretepage.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
public class LoginController {

    @RequestMapping(value="/login", method = RequestMethod.GET)
    public String login(){
        return "redirect:pages/login.jsp";
    }

    @RequestMapping(value="pages/userCheck", method = RequestMethod.POST)
    public String userCheck(ModelMap model, HttpServletRequest request) {
        String name=request.getParameter("name");
        String pwd=request.getParameter("pwd");
        if("concretepage".equalsIgnoreCase(name)&&"concretepage".equalsIgnoreCase(pwd)){
            model.addAttribute("message", "Successfully logged in.");

        }else{
            model.addAttribute("message", "Username or password is wrong.");
        }
        return "redirect:success.jsp";
    }

}

What's my mistake?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Mohamed Safi
  • 39
  • 2
  • 10

1 Answers1

0

You have not placed the Mapping for root path '/' change this code

    @RequestMapping(value="/login", method = RequestMethod.GET)
public String login(){
    return "redirect:pages/login.jsp";
} 

into

    @RequestMapping(value="/", method = RequestMethod.GET)
public String login(){
    return "redirect:pages/login.jsp";
}  

and check the output.

Tahir Hussain Mir
  • 2,506
  • 2
  • 19
  • 26