1 18 19 package org.apache.struts.webapp.tiles.lang; 20 21 import java.util.Locale ; 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 import javax.servlet.http.HttpSession ; 25 import org.apache.struts.action.Action; 26 import org.apache.struts.action.ActionForm; 27 import org.apache.struts.action.ActionForward; 28 import org.apache.struts.action.ActionMapping; 29 import org.apache.struts.taglib.tiles.ComponentConstants; 30 31 public final class SelectLocaleAction extends Action { 32 33 34 36 37 52 public ActionForward execute( 53 ActionMapping mapping, 54 ActionForm form, 55 HttpServletRequest request, 56 HttpServletResponse response) 57 throws Exception { 58 59 String requested = (String )request.getParameter( "language" ); 61 62 if( requested == null ) 63 return (mapping.findForward("failed")); 64 if( requested.equalsIgnoreCase( "FR" ) ) 65 setLocale( request, Locale.FRANCE ); 66 if( requested.equalsIgnoreCase( "UK" ) ) 67 setLocale( request, Locale.UK ); 68 if( requested.equalsIgnoreCase( "DE" ) ) 69 setLocale( request, Locale.GERMAN ); 70 71 return (mapping.findForward("success")); 74 } 75 76 protected void setLocale( HttpServletRequest request, Locale locale ) 77 { 78 HttpSession session = request.getSession(false); 79 if (session != null) 80 session.setAttribute(ComponentConstants.LOCALE_KEY, locale); 81 82 } 83 } 84 | Popular Tags |