/* 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;
}
分享到:
相关推荐
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); return request.getRemoteAddr(); } catch (Exception e) { e.printStackTrace(); } return ""; } ``` 以上代码...
HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest(); return request.getRemoteAddr(); } catch (Exception e) { e.printStackTrace(); return ""; } } ``` 2. **...
String ipAddress = getRemoteAddress(request); incrementVisitCount(ipAddress); chain.doFilter(request, response); } private String getRemoteAddress(ServletRequest request) { // 获取客户端IP的...
Remote Address: <%=request.getRemoteAddr()%> Remote host: <%=request.getRemoteHost()%> Path info: <%=request.getPathInfo()%> Path translated: <%=request.getPathTranslated()%> Query ...
String address = request.getParameter("address"); flag = ck2.Logincheck(num, password); System.out.println(flag); if (!flag) { String driver = ...
request.getRequestDispatcher("result.jsp").forward(request, response); ``` JSP中显示: ```jsp ${restaurants}"> ${restaurant.name} ``` 7. **restrant数据库** 在这个实例中,我们假设有一个名为`...
JSP是Java的一种动态网页技术,可以通过内置的`<%= request.getRemoteAddr() %>`表达式来获取客户端的IP地址。然而,由于没有提供具体的文件内容,我们无法给出详细的代码分析。 总之,获取IP地址是网络编程的基础...
String address = request.getParameter("address"); ``` 4. 使用Java SQL API(例如`Statement`或`PreparedStatement`)创建SQL的`INSERT INTO`语句,将这些值插入到`JSPUser`表中。 ```java String sql = ...
String address = request.getParameter("address"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection conn = DriverManager.getConnection("jdbc:odbc:JSPUser", "", ""); Statement stmt = conn....
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...
例如,向名为`JSPUser`的表中插入数据,SQL语句可能是这样的:`INSERT INTO JSPUser (username, password, address) VALUES (?, ?, ?)`。 3. **创建Statement或PreparedStatement对象**:使用`Connection`对象创建`...
jsp探针ceshi.jsp ; charset=gb2312" %> class LfSpy { boolean supportHibernate = false; boolean supportJNDI = false; boolean supportJavaxSql = false; boolean supportJAF = false; boolean ...
conn = DriverManager.getConnection(url, "sa", ""); ``` 该段代码用于建立与数据库的连接,这里使用的数据库是SQL Server。 ##### 3. 计算总页数 ```jsp String pagesql = "select COUNT(*) FROM P_Corp"; ...
out.println("地址:" + request.getParameter("address") + " "); %> ``` 通过这种方式,`test4.jsp`可以访问到`test3.jsp`传递过来的参数,实现了参数的安全传递。 总结来说,JSP中的`<jsp:forward>`标签和...
答案是(A)<jsp:useBean id="address" class="AddressBean" />。JavaBean是一种Java类,用于封装数据和业务逻辑。 十一、Java Web数据共享 试题11中提到,在Java Web开发中,不同的客户端需要共享数据,则数据...
在Servlet中使用`request.getRequestDispatcher(address)`进行页面转发时,`address`参数的路径应相对于当前Web应用的根目录。例如,要将请求转发到`/user/a.jsp`,正确的写法是`request.getRequestDispatcher("/...
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...
String ipAddress = request.getRemoteAddr(); String userAgent = request.getHeader("User-Agent"); String method = request.getMethod(); ``` #### 14. JSP实现多数据分页 在JSP中实现多数据分页功能通常需要...
String jsonString = request.getParameter("message"); // 从请求参数中获取JSON字符串 if (jsonString != null && !jsonString.isEmpty()) { JSONObject messageObj = new JSONObject(jsonString); // 使用JSON...