Explore. Dream. Discover.

Samuel Chen's life

Twenty years from now you will be more disappointed by
the things that you didn't do than by the ones you did do.
So throw off the bowlines. Sail away from the safe harbor.
Catch the trade winds in your sails.

Explore. Dream. Discover.
—— Mark Twain

2004年7月29日 星期四

Spring MVC 中的国际化的message.properties该如何配置?

ResourceBundle [messages] not found for MessageSource: Can't find bundle for base name messages, locale zh_CN。

为了解决这个,我复制了一个message_zh_CN.properties,但是无论是放在message.properties相同的class目录下,还是放在class/i18n/ 下都仍然是这个警告。

该如何解决呢?

已解决,漏了s
messages is not message.
I've missed the letter 's'. :(

标签: ,

2004年7月28日 星期三

The flow of MVC in Spring -- Part I -- Dispatcher and Controller

From the example on spring official site, I conclude the flow of Spring's MVC.

1. Request --> org.springframework.web.servlet.DispatcherServlet --> parse [ServletName]-servlet.xml --> dispatch to Controller
The “Request” is the “url-patten” mapped in web.xml of web application.
[ServletName] is the name DispatcherServlet mapped (you can also extend it).

2. Create your own Controller “MyController“ --> implement Interface org.springframework.mvc.Controller --> write code of controlling in method handleRequest() which inherited from “Controller” --> return the created model and view obejcts of org.springframework.mvc.ModelAndView --> the framework will render it automatically
The constructor of ModelAndView takes 1 or 3 parameter(s).

For 3 parameters, first one is the view path (The truth path or resolved path. The resolved path is resolved by org.springframework.web.sevrlet.view.InternalResourceViewResolver. I will explain it when I post the next time.).
The second one is the model object's given name, it's String. This name is NOT the object's variant-name. This name will be used in jsp. You can look it as an alias.
The third one is the model object ( just the variant you will pass to jsp view ).

3. Ok, Use the returned model object in jsp.

I am an beginner of Java, so i can not conclude if the flow is the common MVC flow.

to be continue ...

标签: ,

2004年7月26日 星期一

Config Log4J for Spring in WSAD

In SpringFramework, for logging by Log4J subsystem, we can config it with the file named log4j.properties and put it in the folder web-inf/class/ (If using WSAD, you should put it in JavaSource/. It will be deployed to web-inf/class.).
The content of a log4j.properties file like this:

log4j.rootCategory=INFO, stdout, logfile
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - %n

log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=/home/trisberg/jakarta-tomcat-4.1.24/logs/springapp.log
log4j.appender.logfile.MaxFileSize=512KB
# Keep three backup files
log4j.appender.logfile.MaxBackupIndex=3
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
#Pattern to output : date priority [category] - line_separator
log4j.appender.logfile.layout.ConversionPattern=%d %p [%c] - %n

The item “log4j.appender.logfile.file“ is the path.

标签: ,

关于第三方库引用的问题

在用WSAD5.1.1学习 Spring MVC 的过程中,已经引用了Spring.jar,然后把*.HTM map 到 org.springframework.web.servlet.DispatcherServlet,结果在访问*.htm的时候出错,就是说这个servlet unavailable(503还是505).

后来重新写了一个servlet,map *.html, 结果访问正常。

然后又override DispatcherServlet,用 *.go 去 map,结果run on server时出错,错误如下,


Caused by: java.lang.NoClassDefFoundError: org/springframework/web/servlet/DispatcherServlet


为什么找不到呢?

后来是这么解决的:
将原来引用的spring.jar去掉,然后复制spring.jar到web-inf/lib下,wsad会自动引用到项目:)(应该自己再加入也行)

结论:
Java的web项目中,第三方库的引用需要放到web-inf/lib下才能够在打包war时打进去,从而在部署时部署到目标机器上。难倒WSAD不会将引用的3rd库打进去?有待验证。

标签: ,

这个世界不只有.Net:,don't pay so much attention to language

其实技术这个东西,是不分国界,不分语言的 —— 所以也不应该分“语言”吧 :-)。

所以呢,也就冒着被拍死的大不为,在这个.Net的地方记录一点关于Java的心得(MS和Sun都和解了,我怕什么)。

开了一个Spring的category。Spring是一个基于AOP思想的框架,可伸缩性非常的强。目前完成的是Java语言的implementation,而.Net的正在进行中,呵呵,也不算离题太远。

关于Spring Framework的信息可以到 www.springframework.org (java) 和 www.springframework.net (.net) 浏览。

标签: ,