There is no direct support for such a approach in the framework, if
you use Apache HTTP you can add reverse proxy with mod_rewrite plus a
small interceptor, eg.

1. Apache mod_rewrite (inbound):



RewriteEngine On
  RewriteCond %{REQUEST_URI} ^/([a-z]{2})(/.*)?$
  RewriteRule ^/([a-z]{2})(/.*)?$ $2 [E=STRUTS_LOCALE:$1,PT]
  RequestHeader set X-Struts-Locale "%{STRUTS_LOCALE}e"
env=STRUTS_LOCALE

2. Simple interceptor to read the header:

  public class UrlLocaleInterceptor extends AbstractInterceptor {


                                                     @Override



                                                       public String
intercept(ActionInvocation invocation) throws Exception {


                                 HttpServletRequest request =
ServletActionContext.getRequest();


            String locale = request.getHeader("X-Struts-Locale");


                                                               if
(locale != null) {



     ActionContext.getContext().withLocale(LocaleUtils.toLocale(locale));


                                        }



                                                    return
invocation.invoke();


                                                          }



                                                                  }

3. Outbound redirect handling - either via Apache Header edit
directive, or a custom result type that prepends the locale to
Location headers.

Cheers
Łukasz

śr., 14 sty 2026 o 10:51 Florian Schlittgen <[email protected]> napisał(a):
>
> Hi,
>
> in my Struts2 application, I want the user's current language to be part
> of the URL. For example:
>
> http://localhost:8080/myApp/en/my/namespace/myAction.action (English)
> http://localhost:8080/myApp/de/my/namespace/myAction.action (German)
>
> Is there a built-in feature in Struts to implement this?
> I am using the convention plugin and the application contains a lot of
> actions and JSP pages, therefore I looking for way to implement this
> without changing existing namespaces or JSP pages.
> Anyone who have done this before or have any advice on this?
>
> Instead of implementing it with Struts, I could use my reverse proxy
> (Apache HTTP) to rewrite requests (strip out the language part from the
> url and turn it into a request parameter). And for the reverse
> direction, redirects coming from Struts backend must also be rewritten
> (transform the 'Location' response header into the URL form from above).
> Any thoughts or advice on this?
>
> Which one would be the better approach?
>
> Kind regards
> Florian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to