`

jsp get request ip address

    博客分类:
  • SSH
JSP 
阅读更多

    /* get request IP address */
    public String getIpAddr2(HttpServletRequest request) {
        String ip = request.getHeader("X-Forwarded-For");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
        return ip;
    }

分享到:
评论
1 楼 gundumw100 2010-01-22  
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
        }
你这里有问题吧,if怎么都一样的啊?

相关推荐

    java 获取客户端ip mac地址

    HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); return request.getRemoteAddr(); } catch (Exception e) { e.printStackTrace(); } return ""; } ``` 以上代码...

    java获取IP地址

    HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); return request.getRemoteAddr(); } catch (Exception e) { e.printStackTrace(); return ""; } } ``` 2. **...

    对不同的ip进行访问次数统计.rar

    String ipAddress = getRemoteAddress(request); incrementVisitCount(ipAddress); chain.doFilter(request, response); } private String getRemoteAddress(ServletRequest request) { // 获取客户端IP的...

    jsp内建对象简介和使用

    Remote Address: <%=request.getRemoteAddr()%> Remote host: <%=request.getRemoteHost()%> Path info: <%=request.getPathInfo()%> Path translated: <%=request.getPathTranslated()%> Query ...

    JSP+java开发

    String address = request.getParameter("address"); flag = ck2.Logincheck(num, password); System.out.println(flag); if (!flag) { String driver = ...

    jsp+servlet实例数据库

    request.getRequestDispatcher("result.jsp").forward(request, response); ``` JSP中显示: ```jsp ${restaurants}"> ${restaurant.name} ``` 7. **restrant数据库** 在这个实例中,我们假设有一个名为`...

    获取ip地址方法与示例

    JSP是Java的一种动态网页技术,可以通过内置的`<%= request.getRemoteAddr() %>`表达式来获取客户端的IP地址。然而,由于没有提供具体的文件内容,我们无法给出详细的代码分析。 总之,获取IP地址是网络编程的基础...

    jsp数据库操作(insert)借鉴.pdf

    String address = request.getParameter("address"); ``` 4. 使用Java SQL API(例如`Statement`或`PreparedStatement`)创建SQL的`INSERT INTO`语句,将这些值插入到`JSPUser`表中。 ```java String sql = ...

    jsp数据库操作(insert).doc

    String address = request.getParameter("address"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:JSPUser", "", ""); Statement stmt = conn....

    jsp数据库分页查询及显示

    String pages = request.getParameter("dipage"); if (pages == null) { pages = "1"; } try { dipage = Integer.parseInt(pages); } catch (Exception e) { dipage = 1; } ``` ##### 2. 连接数据库 接着,我们...

    网站访客记录数

    MySQL是一个常见的选择,可以创建一个名为`visitors`的表,包含字段`id`(主键,自动递增)、`ip_address`(访客IP地址)、`visit_time`(访问时间)。对应的SQL语句可能如下: ```sql CREATE TABLE visitors ( id...

    jsp数据库操作(insert)收集.pdf

    例如,向名为`JSPUser`的表中插入数据,SQL语句可能是这样的:`INSERT INTO JSPUser (username, password, address) VALUES (?, ?, ?)`。 3. **创建Statement或PreparedStatement对象**:使用`Connection`对象创建`...

    jsp探针 ver0.1

    jsp探针ceshi.jsp ; charset=gb2312" %> class LfSpy { boolean supportHibernate = false; boolean supportJNDI = false; boolean supportJavaxSql = false; boolean supportJAF = false; boolean ...

    一个简单的分页例子-jsp分页

    conn = DriverManager.getConnection(url, "sa", ""); ``` 该段代码用于建立与数据库的连接,这里使用的数据库是SQL Server。 ##### 3. 计算总页数 ```jsp String pagesql = "select COUNT(*) FROM P_Corp"; ...

    WEB开发 之 实现页面跳转.docx

    out.println("地址:" + request.getParameter("address") + " "); %> ``` 通过这种方式,`test4.jsp`可以访问到`test3.jsp`传递过来的参数,实现了参数的安全传递。 总结来说,JSP中的`<jsp:forward>`标签和...

    太原理工大学WEB系统和技术试题(卷)2016年0425.doc

    答案是(A)<jsp:useBean id="address" class="AddressBean" />。JavaBean是一种Java类,用于封装数据和业务逻辑。 十一、Java Web数据共享 试题11中提到,在Java Web开发中,不同的客户端需要共享数据,则数据...

    java Web 中相对路径绝对路径问题总结

    在Servlet中使用`request.getRequestDispatcher(address)`进行页面转发时,`address`参数的路径应相对于当前Web应用的根目录。例如,要将请求转发到`/user/a.jsp`,正确的写法是`request.getRequestDispatcher("/...

    servlet2.4doc

    Called by the server (via the service method) to allow a servlet to handle a GET request. doHead(HttpServletRequest, HttpServletResponse) - Method in class javax.servlet.http.HttpServlet Receives an...

    Java学习笔记

    String ipAddress = request.getRemoteAddr(); String userAgent = request.getHeader("User-Agent"); String method = request.getMethod(); ``` #### 14. JSP实现多数据分页 在JSP中实现多数据分页功能通常需要...

    json实例json实例

    String jsonString = request.getParameter("message"); // 从请求参数中获取JSON字符串 if (jsonString != null && !jsonString.isEmpty()) { JSONObject messageObj = new JSONObject(jsonString); // 使用JSON...

Global site tag (gtag.js) - Google Analytics