标签:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
PrintWriter out=response.getWriter();
String messsge=null;
// 获取请求头User-Agent字段的内容(用于检测浏览器的类型)
String userAgent =request.getHeader("User-Agent");
if ((userAgent!=null)&& (userAgent.indexOf("MSIE") !=-1) ) {
messsge="客户端的浏览器是:Ie";
}else if ((userAgent!=null)&& userAgent.indexOf("Chrome") !=-1) {
messsge="客户端的浏览器是:谷歌浏览器";
}else {
messsge="客户端的浏览器是:其他浏览器";
}
out.println("<html>");
out.println("<head>");
out.println("<title>返回内容</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>"+messsge+"</h1>");
out.println("/<body>");
out.println("/<html>");
out.close();
标签:
原文地址:http://www.cnblogs.com/sdswl/p/5801186.html