Tuesday, April 19, 2011

get window scroll bar width

浏览器因为操作系统或者系统主题不同,导致当前窗口中的scrollbar的宽度不一致,在web应用中影响了页面布局,下述方法可以获取到当前浏览器的滚动条宽度:


function getScrollBarWidth () {
var inner = document.createElement('p');
inner.style.width = "100%";
inner.style.height = "200px";

var outer = document.createElement('div');
outer.style.position = "absolute";
outer.style.top = "0px";
outer.style.left = "0px";
outer.style.visibility = "hidden";
outer.style.width = "200px";
outer.style.height = "150px";
outer.style.overflow = "hidden";
outer.appendChild (inner);

document.body.appendChild (outer);
var w1 = inner.offsetWidth;
outer.style.overflow = 'scroll';
var w2 = inner.offsetWidth;
if (w1 == w2) w2 = outer.clientWidth;

document.body.removeChild (outer);

return (w1 - w2);
};


Reference:http://www.alexandre-gomes.com/?p=115
http://www.softcomplex.com/docs/get_window_size_and_scrollbar_position.html

Monday, April 18, 2011

The classpath*: prefix of java

When constructing an XML-based application context, a location string may use the special classpath*: prefix:


ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml");

This special prefix specifies that all classpath resources that match the given name must be obtained (internally, this essentially happens via a ClassLoader.getResources(...) call), and then merged to form the final application context definition.

Classpath*: portability
The wildcard classpath relies on the getResources() method of the underlying classloader. As most application servers nowadays supply their own classloader implementation, the behavior might differ especially when dealing with jar files. A simple test to check if classpath* works is to use the classloader to load a file from within a jar
on the classpath:

getClass().getClassLoader().getResources("someFileInsideTheJar").

Try this test with files that have the same name but are placed inside two different locations.
In case an inappropriate result is returned, check the application server documentation for settings that might affect the classloader behavior.

The "classpath*:" prefix can also be combined with a PathMatcher pattern in the rest of the location path, for example "classpath*:META-INF/*-beans.xml". In this case, the resolution strategy is fairly simple: a ClassLoader.getResources() call is used on the last non-wildcard path segment to get all the matching resources in the class loader hierarchy, and then off each resource the same PathMatcher resoltion strategy described above is used for the wildcard subpath.

Memo: This article content copied from spring 3.0 framework reference PDF file.

linux命令nc使用实例说明

使用netcat检查服务器的指定的端口是否开通:
root@localhost:~$ nc -z -v 192.168.1.242 80
linux.local [192.168.1.242] 80 (www) open

使用netcat扫描端口:
root@localhost:~$ nc -z -v -w 1 192.168.1.242 1-100
linux.local [192.168.1.242] 80 (www) open
linux.local [192.168.1.242] 22 (ssh) open

使用netcat模拟HTTP请求:
root@localhost:~$ nc www.google.com.hk 80
GET / HTTP/1.1
Host: www.google.com.hk
User-Agent: google-chrome9

HTTP/1.1 200 OK
Date: Mon, 18 Apr 2011 08:56:03 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=Big5
Set-Cookie: PREF=ID=5006f5c292697224:FF=0:NW=1:TM=1303116963:LM=1303116963:S=Lr6ijyXSbmjA6bmZ; expires=Wed, 17-Apr-2013 08:56:03 GMT; path=/; domain=.google.com.hk
Set-Cookie: NID=46=ky6egq_YajJNEzdnM39_2u3CFq2hJLvSVuQm6BokYXSBKhAefFIuL-ZsZOvnDpMISnI2glY25IZxS8_5G0V-EHj-oEc7KRGW4rSZk9yIRnCgsPnm43qhLUMb9hJuKeVW; expires=Tue, 18-Oct-2011 08:56:03 GMT; path=/; domain=.google.com.hk; HttpOnly
Server: gws
X-XSS-Protection: 1; mode=block
Transfer-Encoding: chunked
[......]