title: Spring MVC jsp mapping
body: <p>Hello I am new to Spring and stuck on my jsp mapping - my pages give out the 404 - Page not found error.</p>
  
  <p><strong>My Project Structure is</strong></p>
  
  <pre><code>
  
      WebContent
       + META-INF
       - WEB-INF
        - jsp
          index.jsp
          login.jsp
        +lib
        springMVC-servlet.xml
        web.xml
  
  </code></pre>
  
  <p>Web.xml</p>
  
  <pre><code>
  
  
       &lt;display-name>spring&lt;/display-name>
          &lt;servlet>
               &lt;servlet-name>springMVC&lt;/servlet-name>
               &lt;servlet-class>org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class>
              &lt;load-on-startup>1&lt;/load-on-startup>  
          &lt;/servlet>
  
       &lt;servlet-mapping>
        &lt;servlet-name>springMVC&lt;/servlet-name>
        &lt;url-pattern>/&lt;/url-pattern>
       &lt;/servlet-mapping>
       &lt;welcome-file-list> 
        &lt;welcome-file>index.jsp&lt;/welcome-file> 
      &lt;/welcome-file-list>
      &lt;/web-app>
      </code></pre>
  
  <p>springMVC-servlet.xml</p>
  
  <pre><code>
  
      &lt;?xml version="1.0" encoding="UTF-8"?>
      &lt;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-3.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">
  
          &lt;context:component-scan
              base-package="web.controller" />
  
       &lt;!-- Enabling Spring MVC configuration through annotations -->
       &lt;mvc:annotation-driven />
  
          &lt;bean id="viewResolver"
              class="org.springframework.web.servlet.view.InternalResourceViewResolver">
              &lt;property name="prefix" value="/WEB-INF/jsp/" />
              &lt;property name="suffix" value=".jsp" />
          &lt;/bean>
      &lt;/beans>
  
  </code></pre>
  
  <p>HomeController</p>
  
  <pre><code>
  
      @RequestMapping(method=RequestMethod.GET, value="/")
              public String index(){
                      return "index";
              }
  
              @RequestMapping(value="/login")
              public String login() {
                  return "login";
              }
  
  </code></pre>
  
  <p>I am able to load the <code>http://localhost:8080/Spring3/ </code></p>
  
  <p>The index.jsp has the following code - </p>
  
  <pre><code>
  
      &lt;%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
      &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
      &lt;%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
      &lt;html>
      &lt;head>
      &lt;title>Login&lt;/title>
      &lt;/head>
      &lt;body>
      &lt;c:url value="login.jsp" var="somevar" />
      &lt;h1>Click here to &lt;/h1> &lt;a href= "${somevar}">Login&lt;/a>   
      &lt;/body>
      &lt;/html>
  
  </code></pre>
  
  <p>However when I click the link to the login page - I get the 404 page.</p>
  
  <p>I am not sure what is going wrong - Can anyone help me identify where my mapping is going wrong. </p>