Eclipse/Myeclipse 设置JSP创建默认编码为UTF-8

Categories: Java; Tagged with: ; @ March 25th, 2011 23:00

Eclipse新建JSP默认编码为ISO8859-1, 不支持中文; 调整方法:

Window/Preferences/JSP Files, Encoding设置为: ISO 10646/Unicode(UTF-8)

Myeclipse设置基本同上, 可参考: http://tmsoft.lsxy.com/index.php?load=read&id=922

Java使用SimpleDateFormat设置时间显示到特定时区

Categories: Java; Tagged with: ; @ February 23rd, 2011 21:16

第一次搞乱时区后, 直接修改服务器时区为+8区(See: Linux查看及修改时区).

随着代码的不断扩张, 蔓延到若干角落, 只好用UTC时间, 显示时可使用SimpleDateFormat控制下输出:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
sdf.format(mor.getLastOpen())

如: 2011-02-23 19:13:12

看来我仍然是只三脚猫….:(

网易有道IP, 手机号, 身份证好归属地查询API接口

Categories: Java; Tagged with: ; @ February 23rd, 2011 20:52

http://www.youdao.com/smartresult-xml/search.s?type=ip&q=ip地址

GET后返回XML数据, 包含原IP及归属地.

此外type还可以: mobile(手机号), id(身份证). 尚未发现有限制.

附录: Java通过网易API获取IP归属地.

	static Pattern patternLocation = Pattern.compile("(.+{1,})");
	/**
	 * 根据IP返回归属地.
	 * @param ip
	 * @return
	 */
	private static String getLocationByIP(String ip) {
		String location = "";
		try {
			location = getStringFromUrl(new URL("http://www.youdao.com/smartresult-xml/search.s?type=ip&q=" + ip), "gbk");
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Matcher matcher = patternLocation.matcher(location);
		while (matcher.find()) {
			location = matcher.group(1);
			break;
		}
		System.out.println("归属地: " + location);
		return location;
	}

正则表达式: 电子邮件格式检验

Categories: Java; Tagged with: ; @ February 17th, 2011 15:50

自己用的:

\\w+([-.]\\w+)*@\\w+([-.]\\w+)*\\.[a-z]{2,3}

可能不是最完美的, 但基本没大问题.

Java测试类一并奉上:

	//定义正则表达式
    private static final String REGEX_EMAIL = "\\w+([-.]\\w+)*@\\w+([-.]\\w+)*\\.[a-z]{2,3}";// \\w+([-.]\\w+)*";// "[\\w]+[\\w.]*@(\\w+\\.)+[A-Za-z]+"; // [\\w]+[\\w+.]+\\.\\w+"; //邮件检查正则表达式
    										// \w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String s = "[email protected]";
		System.out.println(s.matches(REGEX_EMAIL));
	}

Facebook Java 开发资料 收集

Categories: Java; Tagged with: ; @ December 4th, 2010 13:41

1. IBM DW 中文:  用 Eclipse Galileo 开发一个 Facebook 应用程序 – Helloworld 必备

2. IMB DW中文:  掌握 Facebook 应用程序开发,使用 PHP、Rational Application Developer、WebSphere Application Server 和 DB2 进行实现,第 1 部分: 安装设置组件

3. TheUnical Technologies: Facebook Java api example to publish on Wall

4. Facebook Doc: http://developers.facebook.com/docs/

5. Facebook-java-api example: http://code.google.com/p/facebook-java-api/wiki/Examples

6. IBM DW: Develop a Facebook application using both PHP and Java programming languages

Newer Posts <-> Older Posts



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.