Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Java»ñÈ¡ÕæʵIPµØÖ·

ÔÚJSPÀ»ñÈ¡¿Í»§¶ËµÄIPµØÖ·µÄ·½·¨ÊÇ£ºrequest.getRemoteAddr()£¬ÕâÖÖ·½·¨Ôڴ󲿷ÖÇé¿ö϶¼ÊÇÓÐЧµÄ¡£µ«ÊÇÔÚͨ¹ýÁËApache,SquidµÈ·´Ïò´úÀíÈí¼þ¾Í²»ÄÜ»ñÈ¡µ½¿Í»§¶ËµÄÕæʵIPµØÖ·ÁË¡£
Èç¹ûʹÓÃÁË·´Ïò´úÀíÈí¼þ£¬½«http://192.168.1.110:2046/ µÄURL·´Ïò´úÀíΪhttp://www.xxx.com/ µÄURLʱ£¬ÓÃrequest.getRemoteAddr()·½·¨»ñÈ¡µÄIPµØÖ·ÊÇ£º127.0.0.1¡¡»ò¡¡192.168.1.110£¬¶ø²¢²»ÊÇ¿Í»§¶ËµÄÕæʵ£É£Ð¡£
¾­¹ý´úÀíÒÔºó£¬ÓÉÓÚÔÚ¿Í»§¶ËºÍ·þÎñÖ®¼äÔö¼ÓÁËÖмä²ã£¬Òò´Ë·þÎñÆ÷ÎÞ·¨Ö±½ÓÄõ½¿Í»§¶ËµÄIP£¬·þÎñÆ÷¶ËÓ¦ÓÃÒ²ÎÞ·¨Ö±½Óͨ¹ýת·¢ÇëÇóµÄµØÖ··µ»Ø¸ø¿Í»§¶Ë¡£µ«ÊÇÔÚת·¢ÇëÇóµÄHTTPÍ·ÐÅÏ¢ÖУ¬Ôö¼ÓÁËX£­FORWARDED£­FORÐÅÏ¢¡£ÓÃÒÔ¸ú×ÙÔ­ÓеĿͻ§¶ËIPµØÖ·ºÍÔ­À´¿Í»§¶ËÇëÇóµÄ·þÎñÆ÷µØÖ·¡£µ±ÎÒÃÇ·ÃÎÊhttp://www.xxx.com/index.jsp/ ʱ£¬Æäʵ²¢²»ÊÇÎÒÃÇä¯ÀÀÆ÷ÕæÕý·ÃÎʵ½ÁË·þÎñÆ÷ÉϵÄindex.jspÎļþ£¬¶øÊÇÏÈÓÉ´úÀí·þÎñÆ÷È¥·ÃÎÊhttp://192.168.1.110:2046/index.jsp £¬´úÀí·þÎñÆ÷ÔÙ½«·ÃÎʵ½µÄ½á¹û·µ»Ø¸øÎÒÃǵÄä¯ÀÀÆ÷£¬ÒòΪÊÇ´úÀí·þÎñÆ÷È¥·ÃÎÊindex.jspµÄ£¬ËùÒÔindex.jspÖÐͨ¹ýrequest.getRemoteAddr()µÄ·½·¨»ñÈ¡µÄIPʵ¼ÊÉÏÊÇ´úÀí·þÎñÆ÷µÄµØÖ·£¬²¢²»ÊÇ¿Í»§¶ËµÄIPµØÖ·¡£
ÓÚÊǿɵóö»ñµÃ¿Í»§¶ËÕæʵIPµØÖ·µÄ·½·¨Ò»£º
public String getRemortIP(HttpServletRequest request) {
if (request.getHeader("x-forwarded-for") == null) {
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for");
}
¿ÉÊǵ±ÎÒ·ÃÎÊhttp://www.xxx.com/index.jsp/ ʱ£¬·µ»ØµÄIPµØַʼÖÕÊÇunknown£¬Ò²²¢²»ÊÇÈçÉÏËùʾµÄ127.0.0.1¡¡»ò¡¡192.168.1.110ÁË£¬¶øÎÒ·ÃÎÊhttp://192.168.1.110:2046/index.jsp ʱ£¬ÔòÄÜ·µ»Ø¿Í»§¶ËµÄÕæʵIPµØÖ·£¬Ð´Á˸ö·½·¨È¥ÑéÖ¤¡£Ô­Òò³öÔÚÁËSquidÉÏ¡£squid.conf µÄÅäÖÆÎļþ¡¡forwarded_for ÏîĬÈÏÊÇΪon£¬Èç¹û forwarded_for Éè³ÉÁË off ¡¡Ôò£ºX-Forwarded-For: unknown
ÓÚÊǿɵóö»ñµÃ¿Í»§¶ËÕæʵIPµØÖ·µÄ·½·¨¶þ£º
public String getIpAddr(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-I


Ïà¹ØÎĵµ£º

Java¸ù¾ÝͼƬ½¨Á¢²»¹æÔò´°ÌåÏê½â

JAVA³ÌÐòµÄÍâ±í×ÜÊÇÒ»°åÒ»Ñ۵ģ¬¿´¶àÁËÄÑÃâÉóÃÀÆ£ÀÍ£¬Äܲ»ÄÜʹÎÒÃǵÄJAVA³ÌÐòÍâ¹Û±äµÃ¸üÃÀ¹Û¸ü¶ÀÌØÄØ£¿´ð°¸Êǿ϶¨µÄ£¬ÎÒÃÇ¿ÉÒÔÈÃJAVA³ÌÐò¸ù¾ÝͼƬÀ´Éú³É×Ô¶¨ÒåµÄ²»¹æÔò´°Ìå¡£±ÈÈçÏÂͼµÄÕâÖÖÍâ¹Û£º
ͼÖеÄÕâ¸öÈËÎï(ÀÙÃ×ÀòÑÇ)±ãÊǶ¨ÒåºÃµÄ²»¹æÔò´°Ì壬ÔõôÑù£¿ºÜƯÁÁ°É£¡ÄÇôÈÃÎÒÃÇ¿ªÊ¼Ñ§Ï°°É¡£
    Ê×ÏÈÒªË ......

´ÓC++¸Éµ½×ªÐÍΪjavaÊÇÍ˲½£¬ÕýÈ·Óë·ñ£¿

½ñÌìÔÚ¹äÂÛ̳µÄʱºò¿´µ½ÓÐÈ˽ò½òÀÖµÀ£º´ÓC++¸Éµ½×ªÐÍΪjavaÊÇÍ˲½
ÎÒ²»ÈÏΪÊÇÕâÑù£¬Ê×ÏÈÓ¦¸ÃÒ»¸öÈ˵ÄÐËȤ£¬¼ÓÉÏÕâÃÅÓïÑÔ£¬ÕâÃŹ¤×÷ÊÇ·ñ·ûºÏÄã
¸É×Ô¼ºÏ²»¶µÄÓïÑÔ±àÂë²ÅÊÇ×îÖØÒªµÄ£¬µ±È»java±È½ÏÈÝÒ׵㣬ÎÒÒ²ÊÇÕâÑùÈÏΪµÄ
µ«ÊÇjava²¢²»ÊÇ´ó¼ÒËù˵µÄÄÇôÈÝÒ×£¬µ±½ñÉç»áË­²»¸Ò˵×Ô¼º»ássh£¬µ±ÊÇ×Ô¼ºÎÊÐÄ×Ô¼ºÑ§µÃÓжàºÃ£¬
ÔÚ ......

Effective Java ѧϰ±Ê¼Ç£¨5£©

¾¡Á¿¸´ÓöÔÏ󣬶ø²»ÊÇ´´½¨ÐµĶÔÏó£¬ÌرðÊǵ±Ò»¸ö¶ÔÏóÊÇimmutable£¨²»¿É¸Ä±ä£©µÄʱºò¡£
ÈçString¶ÔÏó£¬
String s= new String(“String”);   ǧÍò²»ÒªÕâÑù×ö£¬ÒòΪÕâÀïʵ¼ÊÉÏ´´½¨ÁËÁ½¸ö¶ÔÏó¡£
Òª±ÜÃâ³öÏÖÕâÑùµÄÇé¿ö£¬
1ÊÇ¿ÉÒÔÓþ²Ì¬¹¤³§º¯Êý£¬À´½â¾ö£¬ÈçÀà¿âÖеÄBoolean.valueOf(“true&rdqu ......

java Servlet¹ýÂËÆ÷

Ò»¡¢Servlet¹ýÂËÆ÷µÄ¸ÅÄ
*******************************************************
Servlet¹ýÂËÆ÷ÊÇÔÚJava Servlet¹æ·¶2.3Öж¨ÒåµÄ£¬ËüÄܹ»¶ÔServletÈÝÆ÷µÄÇëÇóºÍÏìÓ¦¶ÔÏó½øÐмì²éºÍÐ޸ġ£¡¡¡¡¡¡
Servlet¹ýÂËÆ÷±¾Éí²¢²»²úÉúÇëÇóºÍÏìÓ¦¶ÔÏó£¬ËüÖ»ÄÜÌṩ¹ýÂË×÷Óá£Servlet¹ýÆÚÄܹ»ÔÚServlet±»µ÷ÓÃ֮ǰ¼ì²éRequest¶ÔÏó£ ......

JAVA £­CookieºÍSessionרÌâ

Ò»¡¢cookie»úÖƺÍsession»úÖƵÄÇø±ð
*****************************************************************
¾ßÌåÀ´Ëµcookie»úÖƲÉÓõÄÊÇÔÚ¿Í»§¶Ë±£³Ö״̬µÄ·½°¸£¬¶øsession»úÖƲÉÓõÄÊÇÔÚ·þÎñÆ÷¶Ë±£³Ö״̬µÄ·½°¸¡£
ͬʱÎÒÃÇÒ²¿´µ½£¬ÓÉÓڲŷþÎñÆ÷¶Ë±£³Ö״̬µÄ·½°¸ÔÚ¿Í»§¶ËÒ²ÐèÒª±£´æÒ»¸ö±êʶ£¬ËùÒÔsession
»úÖÆ¿ÉÄÜÐèÒª½è ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ