title: How should I redirect from login page to loggedIn page in spring mvc?
body: <p>This is the main controller class. After Login I want it to redirect to the <code>LoggedIn.jsp</code> page but i get a 404 error. Please help.<br />
  I still haven't provided any code for login authentication. I just want to see how redirection works. I'm new to spring MVC and its concepts. Please provide me with suggestions and solution for the same.
  All the code files are given below:</p>
  <h2>HelloController.java</h2>
  <pre><code>package com.example.myproject;
  
  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;    
  
  @Controller
  public class HelloController {
          
      @RequestMapping(value=&quot;/HelloPage&quot; , method=RequestMethod.GET)
      public String showLoginForm()
      {
          return &quot;HelloPage&quot;;
      }
      @RequestMapping(value=&quot;/redirect&quot; , method=RequestMethod.GET)
      public String redirectPage()
      {
          return &quot;redirect:LoggedIn&quot;;
      }
      
      @RequestMapping(value=&quot;/LoggedIn&quot; , method =RequestMethod.GET)
      public String redirectLoggedIn()
      {
          return &quot;LoggedIn&quot;;
      }
  
  }
  </code></pre>
  <h2>HelloPage.jsp</h2>
  <pre><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
  &lt;!--&lt;link rel=&quot;stylesheet&quot; href=&quot;SpringMVCProject/CSS/CSSHelloPage.css&quot; type=&quot;text/css&quot; /&gt;--&gt;
  &lt;title&gt;Employee Management&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;h3 align=&quot;center&quot; style=&quot;font-family: sans-serif;color: brown; font-size: 40px;&quot;&gt; Employee Management System&lt;/h3&gt;
      &lt;form action=&quot;/spring-dispatcher/redirect&quot; method=&quot;POST&quot;&gt;
      &lt;table border=2 align=&quot;center&quot; cellpadding=&quot;20&quot;&gt;
          &lt;tr&gt;
              &lt;td&gt;User name&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;text&quot; name=&quot;LoginTextBox&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;Password&lt;/td&gt;
              &lt;td&gt;&lt;input type=&quot;password&quot; name=&quot;PasswordTextBox&quot; /&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;button name=&quot;SubmitButton&quot; &gt;Submit&lt;/button&gt;&lt;/td&gt;
              &lt;td&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;button name=&quot;CancelButton&quot; &gt;Cancel&lt;/button&gt;&lt;/td&gt;           
          &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/form&gt;
      
      
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <h2>LoggedIn.jsp</h2>
  <pre><code>&lt;%@ page language=&quot;java&quot; contentType=&quot;text/html; charset=ISO-8859-1&quot;
      pageEncoding=&quot;ISO-8859-1&quot;%&gt;
  &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD HTML 4.01 Transitional//EN&quot; &quot;http://www.w3.org/TR/html4/loose.dtd&quot;&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot;&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;p align=&quot;center&quot;&gt; You have logged in successfully !&lt;/p&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <h2>spring-dispatcher-servlet.xml</h2>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot; 
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
  xmlns:context=&quot;http://www.springframework.org/schema/context&quot; 
  xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot; 
  xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
  http://www.springframework.org/schema/context 
  http://www.springframework.org/schema/context/spring-context-3.0.xsd 
  http://www.springframework.org/schema/mvc 
  http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd&quot;&gt; 
  
  &lt;mvc:annotation-driven&gt;&lt;/mvc:annotation-driven&gt;
      
  &lt;context:component-scan base-package=&quot;com.example.myproject&quot; /&gt;
  
  &lt;bean id=&quot;viewResolver&quot;
      class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
      &lt;property name=&quot;prefix&quot;&gt;
          &lt;value&gt;/WEB-INF/&lt;/value&gt;
      &lt;/property&gt;
      &lt;property name=&quot;suffix&quot;&gt;
          &lt;value&gt;.jsp&lt;/value&gt;
      &lt;/property&gt;
      
  &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  <h2>web.xml</h2>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot; xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd&quot; id=&quot;WebApp_ID&quot; version=&quot;3.0&quot;&gt;
    &lt;display-name&gt;SpringMVCProject&lt;/display-name&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;servlet-class&gt;
                  org.springframework.web.servlet.DispatcherServlet
          &lt;/servlet-class&gt;
          &lt;init-param&gt;  
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;&lt;param-value&gt;/WEB-INF/spring-dispatcher-servlet.xml&lt;/param-value&gt;&lt;/init-param&gt;  
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;spring-dispatcher&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>