When u are creating multi-language Struts and JSTL web application, then it is important to change also locale for FMT config… then u can use fmt:message tag to display property:
<fmt:message key=”app.link.locale.text”/>
sample action class below. Enjoy!
import java.util.Locale;
import com.plansolutions.web.action.BaseActionWithSpringIntegration;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.jstl.core.Config;
public class LocaleAction extends BaseActionWithSpringIntegration {
private static String LOCALE_PARAM=”locale”;
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
if (log.isDebugEnabled()) {
log.debug(“Entering ‘LocaleAction’ method…”);
}
if (request.getParameter(LOCALE_PARAM)!=null) {
if (request.getParameter(LOCALE_PARAM).indexOf(“en”)>=0)
setLocale(request, Locale.ENGLISH);
else
setLocale(request, Locale.GERMAN);
}
if (log.isDebugEnabled())
log.debug(“setLocale after=”+request.getSession().getAttribute(“org.apache.struts.action.LOCALE”));
return mapping.findForward(“referer”);
}
@Override
protected void setLocale(HttpServletRequest request, Locale locale) {
super.setLocale(request, locale);
Config.set(request.getSession(), Config.FMT_LOCALE, locale);
if (log.isDebugEnabled())
log.debug(“setLocale=”+locale);
}
}