title: Spring:url not resolving links correctly
body: <p>I'm pretty new to the Spring framework and web applications, though I'm experienced with Java. When I run my site on a local tomcat server the URL is: <code>http://localhost:8080/myApp/</code></p>
  
  <p>Now a request mapping delegates me to my home page with:</p>
  
  <pre><code>@RequestMapping(value = "/", method = RequestMethod.GET)
  public String someMethod(Model model) { ... 
     return "index"; }
  </code></pre>
  
  <p>Now within a file <code>index.xhtml</code> I link to another page with <code>&lt;a href="apps/"&gt;link&lt;/a&gt;</code>
  but when I want to link back to the index page I have to use <code>&lt;a href="../index/"&gt;link&lt;/a&gt;</code>. I searched for a solution and found:</p>
  
  <pre><code>&lt;spring:url value='/apps' var="apps_url" /&gt;
  &lt;a href="${apps_url}"&gt;link&lt;/a&gt;
  </code></pre>
  
  <p>But spring:url always resolves to <code>http://localhost:8080/myApp/</code> - the page that I'm  currently on. In addition, when I just use a link like this: <code>&lt;a href="/otherSite"&gt;link&lt;/a&gt;</code>, it always resolves to <code>http://localhost:8080/otherSite</code> and not <code>http://localhost:8080/myApp/otherSite</code> like I expected. How can I get my link to work? Is <code>http://localhost:8080/myApp</code> implicitly defined as my context or can/should it be changed to <code>http://localhost:8080/</code>?</p>
  
  <p>Also, is there any connection between the URL on local tomcat server and the URL the web application will have when it's published?</p>
  
  <p>Here are some of my application files:</p>
  
  <p>servlet-context.xml:  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
  
      &lt;!-- Enables the Spring MVC @Controller programming model --&gt;
      &lt;annotation-driven /&gt;
  
      &lt;context:component-scan base-package="myApp" /&gt;
  
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;!-- Handles HTTP GET requests for /resources/** and /css/** by efficiently 
      serving up static resources in the ${webappRoot}/resources directory --&gt;
      &lt;resources mapping="/resources/**" location="/resources/" /&gt;
      &lt;resources mapping="/css/**" location="/css/" /&gt;
  
      &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
          &lt;beans:property name="suffix" value=".xhtml" /&gt;
      &lt;/beans:bean&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>excerpt from web.xml:</p>
  
  <pre><code>&lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/spring/root-context.xml&lt;/param-value&gt;
  &lt;/context-param&gt;
  
  &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
  &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;!-- Processes application requests --&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;appServlet&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/appServlet/servlet-context.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;appServlet&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  </code></pre>