request.getRemoteAddr();//获取IP
request.getHeader("User-Agent");//获取操作系统信息、浏览器信息。
1 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 2 // response.sendError(404, "不给看");//设置状态码 3 // response.setHeader("Location", "/Servlet/BServlet");//重定向 4 // response.sendError(302); 5 request.setCharacterEncoding("utf-8"); 6 response.setContentType("text/html;charset=utf-8"); 7 8 // PrintWriter p = response.getWriter(); 9 // p.write("5秒钟后自动跳转!"); 10 // response.setHeader("refresh", "5;url=/Servlet/BServlet");//定时器 11 System.out.println(request.getRemoteAddr()); 12 String userAgent =request.getHeader("User-Agent"); 13 if(userAgent.toLowerCase().contains("firefox")){ 14 System.out.println("火狐"); 15 }else if(userAgent.toLowerCase().contains("chrome")){ 16 System.out.println("谷歌"); 17 }else if(userAgent.toLowerCase().contains("msie")){ 18 System.out.println("ie"); 19 } 20 21 }