title: Spring: Controller @RequestMapping to jsp
body: <p>Using Spring 3.1.2</p>
  
  <p>How do you reference the Annotated value of the CONTROLLER (not method) RequestMapping from a jsp so I can build URL's relative to the Controller. If the method level request mappings are referenced, it will cause my links to not work, so they cannot be part of the this in any way.</p>
  
  <p>For example (Note that this controller's mapping is "/foo/test"):</p>
  
  <pre><code>@Controller
  @RequestMapping("/foo/test")
  public class FooController {
  
      @RequestMapping(value="/this", method=RequestMethod.GET)
      public String getThis() {
          return "test/this";
      }
  
      @RequestMapping(value="/that", method=RequestMethod.GET)
      public String getThat() {
          return "test/that";
      }
  
      @RequestMapping(value="/other", method=RequestMethod.GET)
      public String getOther() {
          return "test/other";
      }
  }
  </code></pre>
  
  <p>...and from my this.jsp:</p>
  
  <pre><code>&lt;%@ taglib uri="http://www.springframework.org/tags" prefix="s"%&gt;
  &lt;s:url value="${controllerRequestMapping}" var="baseUrl"/&gt;
  
  &lt;a href="${baseUrl}/that"&gt;That&lt;/a&gt;
  &lt;a href="${baseUrl}/other"&gt;Other&lt;/a&gt;
  </code></pre>
  
  <p>The reason I need to access the RequestMapping is because my views may be accessed from multiple Controllers. Note that this controller's mapping is "/bar/test"!</p>
  
  <pre><code>@Controller
  @RequestMapping("/bar/test")
  public class BarController {
  
      @RequestMapping(value="/this", method=RequestMethod.GET)
      public String getThis() {
          return "test/this";
      }
  
      @RequestMapping(value="/that", method=RequestMethod.GET)
      public String getThat() {
          return "test/that";
      }
  
      @RequestMapping(value="/other", method=RequestMethod.GET)
      public String getOther() {
          return "test/other";
      }
  }
  </code></pre>
  
  <p>Some of my Controller level request mappings have path variables too, so getting just the string value of the request mapping will not work. It will have to be resolved:</p>
  
  <pre><code>@Controller
  @RequestMapping("/something/{anything}/test/")
  public class SomethingController {
  ...
  }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>Maybe if there was a way to modify the context path by appending the Controller request mapping to it BEFORE the Spring URL tag, that would solve the problem. </p>
  
  <pre><code>contextPath = contextPath/controllerRequestMapping
  </code></pre>
  
  <p>Then, I could do something like this because I believe Spring will automatically retrieve the current context path:</p>
  
  <pre><code>&lt;%@ taglib uri="http://www.springframework.org/tags" prefix="s"%&gt;
  
  &lt;a href="&lt;s:url value="/that"/&gt;"&gt;That&lt;/a&gt;
  &lt;a href="&lt;s:url value="/other"/&gt;"&gt;Other&lt;/a&gt;
  </code></pre>
  
  <p>This, of course, would be optimal! Ideas? Thoughts...?</p>
  
  <p>Thanks in advance!</p>