title: Spring mvc redirect to different application on different jvm
body: <p>My requirement is to redirection between two different apps in different JVMs.  And also transfer data between the two.  I tried using Flash Attributes, but in the controller, the attributes are null.  I tried creating an interceptor also, but even there the flash attributes are null.  Can anyone help me on how to pass attributes between two different applications?</p>
  
  <p>Here is my code:
  poc1 - calling application</p>
  
  <p>dispatcher-servlet.xml</p>
  
  <pre><code>    &lt;context:component-scan base-package="controller" /&gt;
      &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/views/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean name="flashMapManager" class="org.springframework.web.servlet.support.SessionFlashMapManager" /&gt;
      &lt;mvc:annotation-driven /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Controller.java</p>
  
  <pre><code> @RequestMapping(value = "add", method = RequestMethod.POST)
      public String add(@ModelAttribute("customer") Customer customer,
              final RedirectAttributes redirectAttributes) {
  
          redirectAttributes.addFlashAttribute("customer", customer);
          redirectAttributes.addFlashAttribute("message", "Added successfully.");
          return "redirect:http://localhost:8080/poc2";
      }
  </code></pre>
  
  <p>poc2 - called application</p>
  
  <p>dispatcher-servlet.xml</p>
  
  <pre><code>&lt;context:component-scan base-package="controller" /&gt;
      &lt;bean
  class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="viewClass"
              value="org.springframework.web.servlet.view.JstlView" /&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/views/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;bean name="flashMapManager"
      class="org.springframework.web.servlet.support.SessionFlashMapManager" /&gt;
      &lt;!-- &lt;bean id="handlerMapping" class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"&gt; 
          &lt;property name="interceptors"&gt; &lt;list&gt; &lt;ref bean="requestInterceptor" /&gt; &lt;/list&gt; 
          &lt;/property&gt; &lt;/bean&gt; --&gt;
      &lt;bean id="requestInterceptor" class="RequestInterceptor" /&gt;
      &lt;mvc:annotation-driven /&gt;
      &lt;mvc:interceptors&gt;
          &lt;ref bean="requestInterceptor" /&gt;
      &lt;/mvc:interceptors&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>Controller.java</p>
  
  <pre><code>@RequestMapping(value = "/", method = RequestMethod.GET)
  public ModelAndView index(Model model, HttpServletRequest request,
          HttpSession session) {
      Map&lt;String, ?&gt; inputFlashMap = RequestContextUtils
              .getInputFlashMap(request);
      Customer cust1 = (Customer) model.asMap().get("customer");
      Customer cust = (Customer) inputFlashMap.get("customer");
      ModelAndView modelMap = new ModelAndView("showCustomer");
      System.out.println("Calling controller");
      return modelMap;
  }
  </code></pre>