import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class for Servlet: CharTest
 */
public class CharTest extends javax.servlet.http.HttpServlet implements
		javax.servlet.Servlet {
	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public CharTest() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest arg0,
	 *      HttpServletResponse arg1)
	 */
	protected void doGet(HttpServletRequest arg0, HttpServletResponse arg1)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		// 从HTTP请求的头信息中获取客户端的语言设置
		String clientLanguage = arg0.getHeader("Accept-Language");
		// 简体中文浏览器
		// if (clientLanguage.equals("zh-cn")) {
		// arg0.setCharacterEncoding("GBK");
		// arg1.setContentType("text/html; charset=GBK");
		// }
		// // 繁体中文浏览器
		// else if (clientLanguage.equals("zh-tw")) {
		// arg0.setCharacterEncoding("BIG5");
		// arg1.setContentType("text/html; charset=BIG5");
		// }
		// // 日文浏览器
		// else if (clientLanguage.equals("jp")) {
		// arg0.setCharacterEncoding("SJIS");
		// arg1.setContentType("text/html; charset=SJIS");
		// }
		// // 缺省认为是英文浏览器
		// else {
		// arg0.setCharacterEncoding("ISO-8859-1");
		// arg1.setContentType("text/html; charset=ISO-8859-1");
		// }

		String s = CharacterTest.getString();
		System.out.println(s);
		arg1.setContentType("text/html");
		arg1.setCharacterEncoding("gb18030");
		PrintWriter out = arg1.getWriter();

		out.println("<html>");
		out.println("<head>");
		out.println("</head>");
		out.println("<body bgcolor=\"white\">");
		out.println("<h1>" + clientLanguage + "</h1>");
		out.println("<h1>" + s + "</h1>");
		out.println("</body>");
		out.println("</html>");
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest arg0,
	 *      HttpServletResponse arg1)
	 */
	protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
	}
}