2010년 1월 3일 일요일

Checking Browser Locale

Checking Browser Locale
Similar to GzipServlet, this tip uses header information for tuning output of our servlets; this one allows you to check the header 'Accept-Language'. If your user has set some language preferences within her own browser, you can read these settings through this header:
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class BrowserLocaleServlet extends HttpServlet {

public void doGet
(HttpServletRequest req,HttpServletResponse res)
throws ServletException, IOException
{
doPost(req,res);
}

public void doPost (HttpServletRequest req,
HttpServletResponse res)
throws ServletException, IOException
{

String userLocale=req.getHeader("Accept-Language");

PrintWriter out=res.getWriter();
res.setContentType("text/html");

out.println("<html>");
out.println("<br>User settings are: "+userLocale);
out.println("</html>");

out.flush();
out.close();
}
}

댓글 없음:

댓글 쓰기