Discussions
Web tier: servlets, JSP, Web frameworks: Struts or servlet: how to handle localization in the path?
-
Struts or servlet: how to handle localization in the path? (3 messages)
- Posted by: Antonio Bello
- Posted on: April 24 2007 13:22 EDT
Hello, I'm working on a Struts 1.1 application. I've added support for localization, now I'd want to allow the app automatically select the correct language by specifying the language in the path, such as: http://www.mysite.com/en/login.do and http://www.mysite.com/it/login.do the app should work even when the language identifier is not specified: http://www.mysite.com/login.do and in this case the default language should be used. I've tried using a servlet filter, and an invoker servlet, but with no results. Well, with teh invoker servlet I've able to do it, the problem is that it intercepts everything (including jsp and so on), and the app doesnt work correctly. Is there any other method to implemetn this kind of language selection? Thanks in advance AntonioThreaded Messages (3)
- Re: Struts or servlet: how to handle localization in the path? by Mike Spiridonov on April 25 2007 09:44 EDT
- Re: Struts or servlet: how to handle localization in the path? by Mike Spiridonov on April 25 2007 09:52 EDT
- Re: Struts or servlet: how to handle localization in the path? by Antonio Bello on April 25 2007 11:29 EDT
- Re: Struts or servlet: how to handle localization in the path? by Mike Spiridonov on April 25 2007 09:52 EDT
-
Re: Struts or servlet: how to handle localization in the path?[ Go to top ]
- Posted by: Mike Spiridonov
- Posted on: April 25 2007 09:44 EDT
- in response to Antonio Bello
Hi I think filters might be of use. However I have to admit the better way to support language switching is to specify a request parameter like http://www.mysite.com/login.do?lng=en once and then retain the language in the session, unless of course you are doing a RESTful application. -
Re: Struts or servlet: how to handle localization in the path?[ Go to top ]
- Posted by: Mike Spiridonov
- Posted on: April 25 2007 09:52 EDT
- in response to Mike Spiridonov
Oops, didn't see you actually mentioned servlet filter in your post. Can you tell me why it didn't work for you? -
Re: Struts or servlet: how to handle localization in the path?[ Go to top ]
- Posted by: Antonio Bello
- Posted on: April 25 2007 11:29 EDT
- in response to Mike Spiridonov
Oops, didn't see you actually mentioned servlet filter in your post. Can you tell me why it didn't work for you?
Hi, thanks for your reply. Well, it didn't work because I was doing it in the wrong way (I was using HttpServletRequest.getPathInfo(), which always returns null). I've done it again, and it partially works, but I still have a problem. This is how I've implemented it. I use this code to get the language, if specified: path = req.getRequestURI(); index = path.indexOf(req.getContextPath()); if (index != -1) path = path.substring(req.getContextPath().length()); if (path.matches("^.*/../.*")) { language = path.substring(1, 3).toLowerCase(); locale = userSession.getLocale(); if ((locale == null) || !locale.getLanguage().equals(language)) userSession.setLocale(new Locale (language)); } the problem is that if I change the language I'm redirected to the login page. By changing the language I mean manually modifying the language specifier, for instance from: http://www.mysite.com/en/page.do or http://www.mysite.com/page.do to http://www.mysite.com/it/page.do I think this is a struts issue, since I've verified the filter is called, but the form action class isn't.