title: Spring MVC: RequestMapping both class and method
body: <p>Is this possible?</p>
  
  <pre><code>@Controller
  @RequestMapping("/login")
  public class LoginController {
  
      @RequestMapping("/")
      public String loginRoot() {
          return "login";
      }
  
      @RequestMapping(value="/error", method=RequestMethod.GET)
      public String loginError() {
          return "login-error";
      }
  
  }
  </code></pre>
  
  <p>I got a 404 error when accessing <code>localhost:8080/projectname/login</code> but not in <code>localhost:8080/projectname/login/error</code>.</p>
  
  <p>Here's my web.xml
      project name</p>
  
  <pre><code>&lt;listener&gt;
      &lt;listener-class&gt;
          org.springframework.web.context.ContextLoaderListener
      &lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/applicationContext.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;servlet&gt;
      &lt;description&gt;&lt;/description&gt;
      &lt;servlet-name&gt;projectname&lt;/servlet-name&gt;
      &lt;servlet-class&gt;
          org.springframework.web.servlet.DispatcherServlet
      &lt;/servlet-class&gt;
  &lt;/servlet&gt;
  
  &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;projectname&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>