zbb20170922 jsp java 获取IP 地址的方法

 jsp java 获取IP 地址的方法

package com.zbb.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/gi")
public class GetIpController {
    @RequestMapping(value = "/gi")
    public String getRemortIP(HttpServletRequest request) {
        String idAddr="";
        String header = request.getHeader("x-forwarded-for");
        if ( header== null) {
            System.out.println("1");
            idAddr= request.getRemoteAddr();
        }else{
            System.out.println("2");
            idAddr=header;
        }
        System.out.println(idAddr);
        return "ui/index";
    }
}

 

posted @ 2017-09-22 11:17  DaryllD  阅读(134)  评论(0编辑  收藏  举报