request获取ip

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        String ip = "192.168.1.11";
        String remote = request.getRemoteAddr();//获得远程访问的ip
        if (remote.equals(ip)) {
            response.sendError(404, "您访问的页面不存在");
        } else {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().print("您的ip是:<h1>" + remote + "</h1>");
        }
    }

 

posted @ 2015-06-11 00:15  sflik  阅读(176)  评论(0编辑  收藏  举报