title: struts2 i18ninterceptor return to same page or action
body: <p>I googled 2 hours for my issue but still could'nt find any sollution.</p>
  
  <p>What I want to do:</p>
  
  <p>I'm using struts2 for an international application so I need multi-language support. Therefor I found the i18n-Interceptor to change the locale with only one parameter to pass through (very cool!). Now I want to change the locale at any point in my application, so that the user can change the language and would be forwarded to the same page or action he cames from. This seems not so easy. I've already tried the following things found on google, but doesn't work for me:</p>
  
  <ol>
  <li><p>Use the acutall URL/URI on the JSP (like "ShowUser.action") and call this with another locale -> No way found to get the full URL or URI in jsp with parameters. URL gives me the current site from tiles (i.e. /content/site/user.jsp) and URI returns me my tiles-layout (i.e. /content/layout.jsp). I've tried request.getRequestUrl() and request.getRequestURI()</p></li>
  <li><p>Use the actionContext to get the full URL for JSP -> no way found..</p></li>
  <li><p>Use the "request.getHeader("referal") in my "ChangeLocale.action" and set this dynamically as redirectAction in struts.xml -> Working but too much code to parse the URL with parameters, etc.)</p></li>
  </ol>
  
  <p>The third point is working with the following code, but I'm looking for a nicer sollution:</p>
  
  <p>The relevant part in struts.xml</p>
  
  <pre><code>  &lt;action name="Locale" class="de.smg.LocaleAction"&gt;
       &lt;interceptor-ref name="i18n"/&gt;
       &lt;interceptor-ref name="basicStack"/&gt;
       &lt;result type="redirectAction"&gt;${forwardAction}&lt;/result&gt;
    &lt;/action&gt;
  </code></pre>
  
  <p>The LocaleAction.java:</p>
  
  <pre><code>public class LocaleAction extends ActionSupport implements ServletRequestAware {
  
  private static final long serialVersionUID = 1L;
  private static final String FALL_BACK_ACTION = "ShowStartPage";
  
  private HttpServletRequest request;
  private String forwardAction = null;
  
  @Override
  public String execute() throws Exception {
      String referer = request.getHeader("referer");
      String action = FALL_BACK_ACTION;
  
      if (referer!=null) {        
          // WeberT: first cut off the protocol, server and port...
          referer = referer.substring(referer.lastIndexOf("/") + 1, referer.length());
  
          // WeberT: then cut of the .action part if available
          int dotPos = referer.indexOf(".");
  
          if (dotPos&gt;0) {
              int qMarkPos = referer.indexOf("?");
              if (qMarkPos&gt; 0 &amp;&amp; dotPos &lt; qMarkPos) {         
                  action = referer.substring(0, dotPos) + referer.substring(qMarkPos, referer.length());
              } else {
                  action = referer.substring(0, dotPos);                  
              }               
          }
          forwardAction = action;
      }
      return SUCCESS;
  }
  
  @Override
  public void setServletRequest(HttpServletRequest request) {
      this.request = request;     
  }
  
  /**
   * @return the forwardAction
   */
  public String getForwardAction() {
      return forwardAction;
  }
   }  
  </code></pre>
  
  <p>So I came i.e. from the action:</p>
  
  <pre><code>http://server:port/ShowUser.action?id=1
  </code></pre>
  
  <p>And on the user Site I switch to another language my LocaleAction will return the forwardAction:</p>
  
  <pre><code>ShowUser?id=1
  </code></pre>
  
  <p>So, this is working but seems to me like the dark side? What is the right solution to solve this (as I thought) "little" problem? Thanks for your answers.</p>
  
  <p>Best regards Thomas :-)</p>