亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

代碼如下,filter里的獲取ip地址運行錯誤,幫忙看一下!

代碼如下,filter里的獲取ip地址運行錯誤,幫忙看一下!

慕斯709654 2023-02-18 12:08:42
public class FiltIp implements Filter {private FilterConfig filterConfig;private int startIp;private int endIp;public void destroy() { }public void doFilter(ServletRequest arg0, ServletResponse arg1,FilterChain arg2) throws IOException, ServletException {HttpServletRequest request =(HttpServletRequest)arg0;HttpServletResponse response =(HttpServletResponse)arg1;String strstartIp=filterConfig.getInitParameter("startIp");String strendIp=filterConfig.getInitParameter("endIp");request.setAttribute("strstartIp", strstartIp);request.setAttribute("strendIp", strendIp);startIp=Integer.parseInt(strstartIp.replace(".", ""));endIp=Integer.parseInt(strendIp.replace(".", ""));String reqIP= request.getRemoteAddr();request.setAttribute("reqIP", reqIP);reqIP=reqIP.replace(".", "");int ip=Integer.parseInt(reqIP);if(ip<startIp||ip>endIp){request.getRequestDispatcher("/last/filtIp.jsp").forward(request, response);}System.out.println("request的過濾");arg2.doFilter(arg0, arg1);System.out.println("response的過濾"); }public void init(FilterConfig arg0) throws ServletException {// TODO Auto-generated method stubthis.filterConfig=arg0;}}
查看完整描述

1 回答

?
精慕HU

TA貢獻1845條經驗 獲得超8個贊

由于 0:0:0:0:0:0:0:1 是ipv6 的地址, 所以, 下面代碼會轉換錯誤。
int ip=Integer.parseInt(reqIP);  
至于如何轉換, 和 startIp, endIp格式有關。

查看完整回答
反對 回復 2023-02-20
  • 1 回答
  • 0 關注
  • 99 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號