-
-
Save wagnerluis1982/48a17252bd4cd83486e448e98b533bd9 to your computer and use it in GitHub Desktop.
Solução para a 1ª Avaliação (Questão 2)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package fanese.web; | |
| import javax.servlet.annotation.WebServlet; | |
| import javax.servlet.http.HttpServlet; | |
| import javax.servlet.http.HttpServletRequest; | |
| import javax.servlet.http.HttpServletResponse; | |
| import java.io.IOException; | |
| import java.util.Locale; | |
| @WebServlet(name = "AV1 Q2", urlPatterns = {"/livro"}) | |
| public class Av12Servlet extends HttpServlet { | |
| protected void doGet(HttpServletRequest request, | |
| HttpServletResponse response) throws IOException { | |
| // Obtém a informação completa de local | |
| Locale locale = request.getLocale(); | |
| // Obtém um código de idioma | |
| String idioma = locale.getLanguage(); | |
| // Redireciona para a página específica da Wikipédia dos idiomas | |
| switch (idioma) { | |
| case "pt": | |
| String url = getUrl(request, "/livro/pt"); | |
| response.sendRedirect(url); | |
| break; | |
| case "fr": | |
| url = getUrl(request, "/livro/fr"); | |
| response.sendRedirect(url); | |
| break; | |
| default: | |
| url = getUrl(request, "/livro/en"); | |
| response.sendRedirect(url); | |
| } | |
| } | |
| private static String getUrl(HttpServletRequest request, String relativePath) { | |
| return request.getContextPath() + relativePath; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment