Get encoding information from HttpServletRequest - Java javax.servlet.http

Java examples for javax.servlet.http:HttpServletRequest

Description

Get encoding information from HttpServletRequest

Demo Code


import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Main{
    public static String encoding(HttpServletRequest request) {
        String encoding = request.getHeader("USER-AGENT").toLowerCase();
        encoding = encoding.indexOf("msie") > 0 ? "GBK" : "UTF-8";

        return encoding;
    }/*from   www .  j  a v a  2s  .  com*/
}

Related Tutorials