franta-hg@177: package cz.frantovo.nekurak.servlet; franta-hg@177: franta-hg@177: import java.io.IOException; franta-hg@177: import java.util.Locale; franta-hg@177: import javax.servlet.ServletException; franta-hg@177: import javax.servlet.http.HttpServlet; franta-hg@177: import javax.servlet.http.HttpServletRequest; franta-hg@177: import javax.servlet.http.HttpServletResponse; franta-hg@177: franta-hg@177: /** franta-hg@177: * franta-hg@177: * @author fiki franta-hg@177: */ franta-hg@177: public class SuperServlet extends HttpServlet { franta-hg@177: franta-hg@177: public static final String PARAMETR_JAZYK = "jazyk"; franta-hg@177: private static final String ATRIBUT_JAZYK = "javax.servlet.jsp.jstl.fmt.locale.session"; franta-hg@177: franta-hg@177: @Override franta-hg@177: protected void doGet(HttpServletRequest požadavek, HttpServletResponse odpověď) throws ServletException, IOException { franta-hg@177: společné(požadavek, odpověď); franta-hg@177: } franta-hg@177: franta-hg@177: /** franta-hg@177: * Společné činnosti, které děláme pro všechny HTTP metody (GET, POST atd.) franta-hg@177: */ franta-hg@177: private void společné(HttpServletRequest požadavek, HttpServletResponse odpověď) throws ServletException, IOException { franta-hg@177: nastavJazyk(požadavek); franta-hg@177: } franta-hg@177: franta-hg@177: /** franta-hg@177: * Pokud se chce uživatel ručně přepnout na jiný jazyk, než jaký posílá jeho prohlížeč. franta-hg@177: */ franta-hg@177: private void nastavJazyk(HttpServletRequest požadavek) { franta-hg@177: String jazyk = požadavek.getParameter(PARAMETR_JAZYK); franta-hg@177: if (jazyk != null) { franta-hg@177: požadavek.getSession().setAttribute(ATRIBUT_JAZYK, new Locale(jazyk)); franta-hg@177: } franta-hg@177: } franta-hg@177: }