2004年7月29日 星期四
2004年7月28日 星期三
The flow of MVC in Spring -- Part I -- Dispatcher and Controller
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 ...
标签: Java, Programming
2004年7月26日 星期一
Config Log4J for Spring in WSAD
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.
关于第三方库引用的问题
后来重新写了一个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) 浏览。
