Re: Re: User's language in URL
[email protected] Wed, 14 Jan 2026 18:38:01 +0000
| Newsgroups | gmane.comp.jakarta.struts.user |
|---|---|
| Message-ID | <trinity-a1b5525a-7f37-4a5a-be9f-742e4a671e5d-1768415881082@trinity-msg-rest-webde-webde-live-589d84f6c9-hg9fb> |
Hi Florian,
I had same problem migrating from Struts1 to Struts7
I solved it with an Interceptor but also used namespace (what you do not w=
ant)
Do you want me to post my solution?
Kind regards Ute
Gesendet mit der mobilen Mail App
Am 14=2E01=2E26 um 13:08 schrieb Florian Schlittgen
> Great, thanks for your quick reply=2E
> One comment:
> > 3=2E Outbound redirect handling - either via Apache Header edit
> > directive, or a custom result type that prepends the locale to
> > Location headers=2E
> With the introduction of a custom result type, you rely on the Apache=20
> rewriting=2E If you want to test the application locally without reverse=
=20
> proxy, the redirect will not work=2E So I rather would go for Apache=20
> Header edit directive to rewrite the Location header to only loosely=20
> couple Apache to the Struts application=2E
>=20
> Cheers
> Florian
>=20
>=20
> On 1/14/26 11:47 AM, Lukasz Lenart wrote:
> > 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=2E
> >
> > 1=2E Apache mod_rewrite (inbound):
> >
> >
> >
> > RewriteEngine On
> > RewriteCond %{REQUEST_URI} ^/([a-z]{2})(/=2E*)?$
> > RewriteRule ^/([a-z]{2})(/=2E*)?$ $2 [E=3DSTRUTS_LOCALE:$1,PT]
> > RequestHeader set X-Struts-Locale "%{STRUTS_LOCALE}e"
> > env=3DSTRUTS_LOCALE
> >
> > 2=2E Simple interceptor to read the header:
> >
> > public class UrlLocaleInterceptor extends AbstractInterceptor {
> >
> >
> > @Override
> >
> >
> >
> > public String
> > intercept(ActionInvocation invocation) throws Exception {
> >
> >
> > HttpServletRequest request =3D
> > ServletActionContext=2EgetRequest();
> >
> >
> > String locale =3D request=2EgetHeader("X-Struts-Locale");
> >
> >
> > if
> > (locale !=3D null) {
> >
> >
> >
> > ActionContext=2EgetContext()=2EwithLocale(LocaleUtils=2EtoLocale=
(locale));
> >
> >
> > }
> >
> >
> >
> > return
> > invocation=2Einvoke();
> >
> >
> > }
> >
> >
> >
> > }
> >
> > 3=2E Outbound redirect handling - either via Apache Header edit
> > directive, or a custom result type that prepends the locale to
> > Location headers=2E
> >
> > Cheers
> > =C5=81ukasz
> >
> > =C5=9Br=2E, 14 sty 2026 o 10:51 Florian Schlittgen <schlittgen@posteo=
=2Ede> napisa=C5=82(a):
> >> Hi,
> >>
> >> in my Struts2 application, I want the user's current language to be p=
art
> >> of the URL=2E For example:
> >>
> >> http://localhost:8080/myApp/en/my/namespace/myAction=2Eaction (Englis=
h)
> >> http://localhost:8080/myApp/de/my/namespace/myAction=2Eaction (German=
)
> >>
> >> Is there a built-in feature in Struts to implement this?
> >> I am using the convention plugin and the application contains a lot o=
f
> >> actions and JSP pages, therefore I looking for way to implement this
> >> without changing existing namespaces or JSP pages=2E
> >> 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 t=
he
> >> url and turn it into a request parameter)=2E And for the reverse
> >> direction, redirects coming from Struts backend must also be rewritte=
n
> >> (transform the 'Location' response header into the URL form from abov=
e)=2E
> >> Any thoughts or advice on this?
> >>
> >> Which one would be the better approach?
> >>
> >> Kind regards
> >> Florian
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts=2Eapache=2Eorg
> >> For additional commands, e-mail: user-help@struts=2Eapache=2Eorg
> >>
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts=2Eapache=2Eorg
> > For additional commands, e-mail: user-help@struts=2Eapache=2Eorg
> >
>=20
>=20
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts=2Eapache=2Eorg
> For additional commands, e-mail: user-help@struts=2Eapache=2Eorg
>=20
>=20