java - localeChangeInterceptor does not work -
i have standard configuration, kept editing many times, checked other questions on final configuration people had issues resolved, no result me. whenever firing requests like:
http://localhost:8080/appname/?lang=es_mx
or
http://localhost:8080/appname?lang=es_mx
not resolve correct locale, nothing.
<bean id="messagesource" class="org.springframework.context.support.reloadableresourcebundlemessagesource"> <property name="basename" value="/web-inf/messages" /> </bean> <bean id="localeresolver" class="org.springframework.web.servlet.i18n.sessionlocaleresolver"></bean> <mvc:interceptors> <bean class="org.springframework.web.servlet.i18n.localechangeinterceptor"> <property name="paramname" value="lang" /> </bean> </mvc:interceptors>
i know default locale resolver headers work messageresource , .jsp configuration correct, since set 1 browser explicitly have es_mx locale , resolves acceptheaderlocaleresolver correctly.
does have way handler mappings defined?
@requestmapping(value = "/", method = requestmethod.get) public string home( model model, locale locale, httpservletrequest hr) { string header = hr.getheader("user-agent"); model.addattribute("header", header); string contextpath = hr.getcontextpath(); model.addattribute("contextpath", contextpath); return "index"; }
god spent time on this...please help
i solved placing interceptor servlet-context.xml instead of other config. trying figure out why in servlet-context.xml works , in dedicated config doesn't, insights valuable ! :-) i not accepting answer, since not explain why. please explain me why case(and test - ideally resulting in interceptor being placed in custom config).
for in trouble try this:
<interceptors> <beans:bean class="org.springframework.web.servlet.i18n.localechangeinterceptor" p:paramname="lang" /> </interceptors>
inside servlet-context.xml
needs namespace:
xmlns:p="http://www.springframework.org/schema/p"
sessionlocaleresolver seems not care location , works in custom config location too.
Comments
Post a Comment