2007年10月17日星期三
2007年10月15日星期一
我的右手-真男人
昨天看了军旅题材的电影《我的右手》,这部片子的主要目的不是为了反映战争场面,而是从一个侧面说明了主人公胡小军的坚强意志,从战斗英雄向生活中的英雄转变的过程。看到后面,看到胡小军激动的说“护士长说她做我的右手”,我突然感到眼眶酸酸的。附上后面的一段歌词:
---------
别人都说那是一座很巍峨的山
而我也知道那是你也会疲倦的肩
别人看到你胸前的荣誉和花环
而我数不清你背后付出的血汗
从来没有风沙让你 让你低过头
从来没有荆棘让你停留
每次把我的手握痛你才走
你的背影是握深情的眼眸
一生只对你微笑
再长的路陪你千里迢迢
虽然你不能给我一个完整的拥抱
我愿温暖你的暮暮朝朝
---------
别人都说那是一座很巍峨的山
而我也知道那是你也会疲倦的肩
别人看到你胸前的荣誉和花环
而我数不清你背后付出的血汗
从来没有风沙让你 让你低过头
从来没有荆棘让你停留
每次把我的手握痛你才走
你的背影是握深情的眼眸
一生只对你微笑
再长的路陪你千里迢迢
虽然你不能给我一个完整的拥抱
我愿温暖你的暮暮朝朝
2007年8月24日星期五
Blogger招谁惹谁了?
这么久了blogspot.com的域名还是不能访问,觉得很奇怪.不过还是对Blogger满怀信心,因为尝试过几个blog程序,还是没有一个可以取代Blogger的地位.Opera的博客已经好几个月不能访问了,据说也是GFW的杰作.唉,算了,反正用inblogs.net还是可以访问的,了解blogger的人会看到,最坏就当我自言自语好了吧.
2007年8月6日星期一
有点想换Java IDE了,想换到Netbeans
一直用Eclipse,从学Java时开始,都好几年了.从2.0的版本开始用的,真的有感情了.
Eclipse很漂亮,3.0之后的版本比2.0漂亮;Eclipse的增量编译很爽.Eclipse的实时语言提示和纠错很爽,总之,用Eclipse编写Java代码是一种享受.
后来实际应用Java时,主要是来做WEB项目,最早的时候使用Tomcat Plugin和lomboz插件来做.在2004年的时候,我在CSDN发了一篇关于使用tomcat plug集成和断点调试的文章到现在时而都有人来邮件询问这方面得问题,我都会回复他们,现在我都不用这些了,用Eclipse的WTP或者直接用JbossIDE绑定的Eclipse,它可以免去许多插件集成的麻烦.然而这却有一些麻烦了.JbossIDE2.0绑定得Eclipse3.2在Linux下很不稳定,问题集中体现在启动Tomcat时总会是不是Crash.这也就是为什么现在手中项目的WEB部分在Windows下开发的原因.我不能使用Linux,总觉得心里不爽.
项目的下一期工程需要开发一个客户端,以弥补WEB页面客户端的一些不足.这面临这两种选择,找一个合适的技术和工具构建Java版本的GUI程序,考虑的当然是SWT和Swing;另外一种方法,是用DotNet来做图形界面程序,那么也就是底层通信协议的程序用C#重新实现,或者用Web-service方式让已有的Java代码和新的客户端程序一起工作.
我找到了Netbeans,先不说别的,它的Swing界面设计器很棒,这是我急切需要的功能.别给我提Eclipse,它的VE简直慢得像蜗牛.但是最初我感到不爽得是它的代码编辑器的字体不好看.我把代码字体设置成Counter new,英文的代码好看了,但是中文就不能显示了.还有在Note book上,菜单的字体偏小,都缩成一团了.后来在网上查了Netbean,才发现它现在已经引起了广泛关注,特别是即将发布的Netbeans6,关于它和Eclipse的比较的文章也很多.其实早在2,3年前我就知道Netbeans,那个时候好像是4.0版本吧,我推荐其他人用它,因为它有中文版本,并且可以绑定JDK,对于某些新手来说,免去了设置等等步骤.我自己觉得它集成的服务器的功能不错,而我自己却没有真正的用过它.一是它看起来没有Eclipse漂亮,特别是代码编辑器.然而这一切似乎都成了过去时了.新的Netbeans,比如现在的最新稳定版本5.5.1,通过设置之后,可以很漂亮:在Windows下把所有语言的缺省字体设置为DialogInput,那么英文字体是等宽的Courier New字体,而中文会用新宋体,这就和Eclipse中的表现一致了.可以调整启动参数使得菜单的字体大起来,比如调整为12pt,那么在我的Note book上显示就相当漂亮了,自然在办公室工作机器的Linux上面使用也会没有问题.有时间试试看吧,如果用起来顺手,就决定转用Netbeans了.并且期待着Netbeans6的稳定版本.据说它的代码编辑器可以赶超Eclipse!不过还能有一点得到满足就完美了,FreeMarker-IDE的NB插件!网上找过了没有,不知道什么时候能有,或者自己来研究一下,尝试能否开发.
Eclipse很漂亮,3.0之后的版本比2.0漂亮;Eclipse的增量编译很爽.Eclipse的实时语言提示和纠错很爽,总之,用Eclipse编写Java代码是一种享受.
后来实际应用Java时,主要是来做WEB项目,最早的时候使用Tomcat Plugin和lomboz插件来做.在2004年的时候,我在CSDN发了一篇关于使用tomcat plug集成和断点调试的文章到现在时而都有人来邮件询问这方面得问题,我都会回复他们,现在我都不用这些了,用Eclipse的WTP或者直接用JbossIDE绑定的Eclipse,它可以免去许多插件集成的麻烦.然而这却有一些麻烦了.JbossIDE2.0绑定得Eclipse3.2在Linux下很不稳定,问题集中体现在启动Tomcat时总会是不是Crash.这也就是为什么现在手中项目的WEB部分在Windows下开发的原因.我不能使用Linux,总觉得心里不爽.
项目的下一期工程需要开发一个客户端,以弥补WEB页面客户端的一些不足.这面临这两种选择,找一个合适的技术和工具构建Java版本的GUI程序,考虑的当然是SWT和Swing;另外一种方法,是用DotNet来做图形界面程序,那么也就是底层通信协议的程序用C#重新实现,或者用Web-service方式让已有的Java代码和新的客户端程序一起工作.
我找到了Netbeans,先不说别的,它的Swing界面设计器很棒,这是我急切需要的功能.别给我提Eclipse,它的VE简直慢得像蜗牛.但是最初我感到不爽得是它的代码编辑器的字体不好看.我把代码字体设置成Counter new,英文的代码好看了,但是中文就不能显示了.还有在Note book上,菜单的字体偏小,都缩成一团了.后来在网上查了Netbean,才发现它现在已经引起了广泛关注,特别是即将发布的Netbeans6,关于它和Eclipse的比较的文章也很多.其实早在2,3年前我就知道Netbeans,那个时候好像是4.0版本吧,我推荐其他人用它,因为它有中文版本,并且可以绑定JDK,对于某些新手来说,免去了设置等等步骤.我自己觉得它集成的服务器的功能不错,而我自己却没有真正的用过它.一是它看起来没有Eclipse漂亮,特别是代码编辑器.然而这一切似乎都成了过去时了.新的Netbeans,比如现在的最新稳定版本5.5.1,通过设置之后,可以很漂亮:在Windows下把所有语言的缺省字体设置为DialogInput,那么英文字体是等宽的Courier New字体,而中文会用新宋体,这就和Eclipse中的表现一致了.可以调整启动参数使得菜单的字体大起来,比如调整为12pt,那么在我的Note book上显示就相当漂亮了,自然在办公室工作机器的Linux上面使用也会没有问题.有时间试试看吧,如果用起来顺手,就决定转用Netbeans了.并且期待着Netbeans6的稳定版本.据说它的代码编辑器可以赶超Eclipse!不过还能有一点得到满足就完美了,FreeMarker-IDE的NB插件!网上找过了没有,不知道什么时候能有,或者自己来研究一下,尝试能否开发.
2007年8月3日星期五
FreeMarker2.3.7开始增加的一个很爽的特性
Webwork自带的FreeMarker是2.3.4版本。Webwork中模版的渲染是基于FreeMarker。今天看Freemarker最新版本2.3.10的文档,发现一个很很爽的特性,'!'操作符。在2.3.7之前的版本,如果你要为java中某个为null的值设置默认值,或者在网页上显示空白,你得这么做。
<#if product.color?exists>${product.color}</#if>
<#if product.color?exists>${product.color}<#else>red</#if>
而在新的FreeMarker中对应可以这么写:
${product.color!},${product.color!'red')
还有一个更爽的是这么写:
${(product.color)!'red'}取代<#if product?exists && product.color?exists>${product.color}<#else>red</#if>
有这样的操作符之后,大大简化了模版的编写,我再也不害怕可能为null值的判断了,反正加个'!'就是。不过要记住,要把Freemarker升级到2.3.7之后的版本哦,否则这个操作符是不被支持的。Freemarker真的是个好东西,方便应用,并且易于扩展,我就用Freemarker的API,编写了一个短信模版引擎用在系统当中。源程序如下:
/*
* This file is part of the Frequent Passenger Service System
* which was created by China Southern Airlines Hunan Branch
* All Rights Reserved, Any organization or individual <b>must not</b>
* modify or re-distribute all of or part of the software at any form without permission.
*
* IT Department of Hunan Branch, China Southern Airlines, Ltd.
*
* Author:Yi Can yican@cs-air.com alva.yi@gmail.com
*
* Version: $Id: TemplateEngine.java 197 2007-06-01 09:40:14Z vulcan $
*/
package com.csair.hunan.pss.web.sms;
* This file is part of the Frequent Passenger Service System
* which was created by China Southern Airlines Hunan Branch
* All Rights Reserved, Any organization or individual <b>must not</b>
* modify or re-distribute all of or part of the software at any form without permission.
*
* IT Department of Hunan Branch, China Southern Airlines, Ltd.
*
* Author:Yi Can yican@cs-air.com alva.yi@gmail.com
*
* Version: $Id: TemplateEngine.java 197 2007-06-01 09:40:14Z vulcan $
*/
package com.csair.hunan.pss.web.sms;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.StringWriter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.commons.logging.LogFactory;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.Template;
/**
* render the template with filling the variables
* based on the syntax of Freemarker
* @author Alva alva.yi@gmail.com yican@cs-air.com
*
*/
public class TemplateEngine {
private static Configuration cfg = new Configuration();
private static Log log = LogFactory.getLog(TemplateEngine.class);
public static String render(Object varMap, SmsTemplate t) {
//builder a reader and a writer for the FreeMarker template engine
StringReader rd = new StringReader(t.getBody());
StringWriter wt = new StringWriter();
try {
Template ft = new Template(t.getName(), rd, cfg);
ft.process(varMap, wt);
} catch (Exception e) {
log.error("Cann't render Template for:" + t.getName());
e.printStackTrace();
}
return wt.getBuffer().toString();
}
}
* render the template with filling the variables
* based on the syntax of Freemarker
* @author Alva alva.yi@gmail.com yican@cs-air.com
*
*/
public class TemplateEngine {
private static Configuration cfg = new Configuration();
private static Log log = LogFactory.getLog(TemplateEngine.class);
public static String render(Object varMap, SmsTemplate t) {
//builder a reader and a writer for the FreeMarker template engine
StringReader rd = new StringReader(t.getBody());
StringWriter wt = new StringWriter();
try {
Template ft = new Template(t.getName(), rd, cfg);
ft.process(varMap, wt);
} catch (Exception e) {
log.error("Cann't render Template for:" + t.getName());
e.printStackTrace();
}
return wt.getBuffer().toString();
}
}
2007年7月30日星期一
解决Webwork,tomcat5.x一起使用时GET方法乱码问题
项目中使用的Framework是Webwork,服务器用的是tomcat5.5.只要统一文件本身编码,charset编码还有webwork.properties中webwork.i18n.encoding=UTF-8的设置,通过表单POST方法提交的中文数据都没有问题,另外项目中间有一些请求是通过Ajax采用Get方法提交的。并且之前由于数据中中文输入项不多,那么我对于提交的数据都用new String(cname.getBytes("ISO-8859-1"), "UTF-8")进行转码,也可以使用。随着要转编码的项越来越多,开始对这种转码的方式感到厌烦,于是想到了从Webwork里面想办法解决。
在FilterDispather.java里找到了这样的一句:
// prepare the request no matter what - this ensures that the proper character encoding
// is used before invoking the mapper (see WW-9127)
DispatcherUtils du = DispatcherUtils.getInstance();
看到DispatcherUtils.java果然Webwork采用的方法和以前解决中文问题用Filter的方式其实一样,无非是先设置request的编码:
public void prepare(HttpServletRequest request, HttpServletResponse response) {
String encoding = null;
if (Configuration.isSet(WebWorkConstants.WEBWORK_I18N_ENCODING)) {
encoding = Configuration.getString(WebWorkConstants.WEBWORK_I18N_ENCODING);
}
Locale locale = null;
if (Configuration.isSet(WebWorkConstants.WEBWORK_LOCALE)) {
locale = LocalizedTextUtil.localeFromString(Configuration.getString(WebWorkConstants.WEBWORK_LOCALE), request.getLocale());
}
if (encoding != null) {
try {
request.setCharacterEncoding(encoding);
} catch (Exception e) {
LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
}
}
if (locale != null) {
response.setLocale(locale);
}
if (paramsWorkaroundEnabled) {
request.getParameter("foo"); // simply read any parameter (existing or not) to "prime" the request
}
}
原来猜想是webwork会对参数做一些包装和处理,但是只是直接取得parameterMap:
public Map createContextMap(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping, ServletContext context) {
// request map wrapping the http request objects
Map requestMap = new RequestMap(request);
// parameters map wrapping the http paraneters.
Map params = null;
if (mapping != null) {
params = mapping.getParams();
}
Map requestParams = new HashMap(request.getParameterMap());
if (params != null) {
params.putAll(requestParams);
} else {
params = requestParams;
}
// session map wrapping the http session
Map session = new SessionMap(request);
// application map wrapping the ServletContext
Map application = new ApplicationMap(context);
return createContextMap(requestMap, params, session, application, request, response, context);
}
由此可以猜想Get的乱码并不是webwork的问题,很可能与tomcat有关。再google了一下发现了tomcat5对get和post方法分开处理,并且request.setCharacterEncoding对get方法没有作用,这需要设置server.xml可以从根本上解决QueryString中文乱码的问题了。具体方法是对Connector元素设置URIEncoding或者useBodyEncodingForURI=true。这样代码中的那些丑陋的转编码设置就可以去掉了。
在FilterDispather.java里找到了这样的一句:
// prepare the request no matter what - this ensures that the proper character encoding
// is used before invoking the mapper (see WW-9127)
DispatcherUtils du = DispatcherUtils.getInstance();
看到DispatcherUtils.java果然Webwork采用的方法和以前解决中文问题用Filter的方式其实一样,无非是先设置request的编码:
public void prepare(HttpServletRequest request, HttpServletResponse response) {
String encoding = null;
if (Configuration.isSet(WebWorkConstants.WEBWORK_I18N_ENCODING)) {
encoding = Configuration.getString(WebWorkConstants.WEBWORK_I18N_ENCODING);
}
Locale locale = null;
if (Configuration.isSet(WebWorkConstants.WEBWORK_LOCALE)) {
locale = LocalizedTextUtil.localeFromString(Configuration.getString(WebWorkConstants.WEBWORK_LOCALE), request.getLocale());
}
if (encoding != null) {
try {
request.setCharacterEncoding(encoding);
} catch (Exception e) {
LOG.error("Error setting character encoding to '" + encoding + "' - ignoring.", e);
}
}
if (locale != null) {
response.setLocale(locale);
}
if (paramsWorkaroundEnabled) {
request.getParameter("foo"); // simply read any parameter (existing or not) to "prime" the request
}
}
原来猜想是webwork会对参数做一些包装和处理,但是只是直接取得parameterMap:
public Map createContextMap(HttpServletRequest request, HttpServletResponse response, ActionMapping mapping, ServletContext context) {
// request map wrapping the http request objects
Map requestMap = new RequestMap(request);
// parameters map wrapping the http paraneters.
Map params = null;
if (mapping != null) {
params = mapping.getParams();
}
Map requestParams = new HashMap(request.getParameterMap());
if (params != null) {
params.putAll(requestParams);
} else {
params = requestParams;
}
// session map wrapping the http session
Map session = new SessionMap(request);
// application map wrapping the ServletContext
Map application = new ApplicationMap(context);
return createContextMap(requestMap, params, session, application, request, response, context);
}
由此可以猜想Get的乱码并不是webwork的问题,很可能与tomcat有关。再google了一下发现了tomcat5对get和post方法分开处理,并且request.setCharacterEncoding对get方法没有作用,这需要设置server.xml可以从根本上解决QueryString中文乱码的问题了。具体方法是对Connector元素设置URIEncoding或者useBodyEncodingForURI=true。这样代码中的那些丑陋的转编码设置就可以去掉了。
订阅:
博文 (Atom)
