ĸ2
һֻHibernateStrutsJ2EEӦÿ
ķHibernateStrutsĻƣһֻHibernateStrutsJ2EEӦÿԡֲУģͲHibernateʵ֣ͼͿStrutsʵ֡ɴʹԼϵͳĿЧʡ
ؼ HibernateStrutsMVC־ò 1
JavaƣΪҵӦõıƽ̨J2EEƽ̨õ˳ķչJ2EE淶аĶEnterprise JavaBean(EJB)Java Servlets(Servlet)Java Server Pages(JSP)Java Message Service(JMS)ȣӦϵͳǣڴͳJ2EEӦõĿҲһЩ⣺
1ģͺģ֮ìܡĿǰʹõݿ϶ǹϵݿ⣬Javaһԣڴ洢ͶȡʱʹSQLJDBCݿ˱̵ЧԼϵͳĿάԣ
2ͳJ2EEӦöûEJBܣֿʺڿҵӦãʹEJBп͵ҪķѴʱ䡣Ϊ˽ʹԣϵͳĿЧʣһֻStrutsܺHibernateܵJ2EEӦÿԡ
2 ݳ־ò㼰Hibernate Hibernateһݳ־òܣһʵֶϵ֮ӳ䣨O/R MappingĹߣJDBCĶװʹԱʹö˼ݿ⡣ṩ˴Javaൽݱӳ䣬ҲṩݲѯͻָơʹJDBCSQLݿ⣬ʹHibernateܴʵֵЧʡHibernateļʽJavaݱ֮ӳϵͬʱڸIJ潫ݱ֮ĹϵΪJava֮ļ̳мȹϵͨʹHQL佫ӵĹϵ
öķʽں̶ܴϼ˶ݵIJѯӿ˿ЧʡHibernateһֱ۵APIڶݿʾĶִвѯҪЩֻڳǽнȻHibernate漴ɡװ־ûҵҪдJDBC䣬Ӷʹݳ־òõ˼ļ
3 StrutsʵMVCܹ MVCModel-View-ControllerTrygve ReenskaugȱӦSmallTalk-80УཻͽϵͳĹɻݽƿɱԵMVCѽϵͳɷֽģ͡ͼ֡ ģͣModelڶʾݺʽµڳװĺݡܵļϵھĽI/OͼViewѱʾģݼϵ״̬ϢضʽչʾûģͻʾϢͬϢжͬʾʽͼControllerǴûĽģְǿṩģκα仯ĴȷûģͼĶӦϵû룬뷴ģͣʵֶģ͵ļƣʹģͺͼЭIJͨһͼӦһģ͡ͼķ룬ʹһģͿԾжʾͼûͨijͼĿıģ͵ݣЩݵͼӦӳЩ仯ˣۺʱ˺ݱ仯Ὣ仯֪ͨеͼʾĸ¡ʵһģ͵ı仯-ơ
StrutsΪApache JakartaĿɲ̳MVCĸԣJ2EEص㣬Ӧı仯չStrutsܺܺõĽJspJava ServletJava BeanTaglibȼStrutsУеMVCпɫActionServletActionServletһͨõĿṩ˴з͵StrutsHTTPڵ㡣ȡ ַЩӦĶࣨЩActionࣩҲӦAction FormFromBeanࣨActionBeanʺҵJava BeanEJBѿȨ
JSPļJSPļͼЩ
Struts-config.xmlļáStrutsУͼҪJSPҳɣStrutsṩḻJSPǩ⣬ڷֿͳģһJava BeanʽڡStrutsУҪBeanֱǣActionActionFormEJBJava Bean Strutsûо嶨ģͲʵ֣ʵʿУģͲͨǺҵģҪԵײݽвһֿԣHibernate뵽StrutsܵģͲУʹݷװӳ䣬ṩ־û֧֡
4 HibernateStrutsJ2EEӦ
J2EEӦзdzձû¼Ϊ˵ϵṹξõġ¼̷dzûӵ¼ҳlogin.jsp¼ϢϵͳԵ¼Ϣ֤ȷɹ¼ʾӦϢ ڿУʹEclipseΪͬʱ˶StrutsHibernateṩõĿƺֵ֧ĵMyEclipseWebʹTomcatݿѡMysql ȶHibernateãֻҪϵͳԶɵ
hibernate.cfg.xmlģúݿӵĸֲԼӳļHibernateӳҪڲԣܲǺܺãͨJNDIΪʹTomcatӳء
ԭ1ӡ壩
Web MVC with the Spring Framework
Juergen Hoeller
1. Introduction: Spring the Application Framework
When first confronted with the Spring Framework, one might be tempted to think: \particularly a web framework but a generic lightweight application framework with dedicated web support, and show the architectural differences to Struts and WebWork In contrast to Struts or WebWork, Spring is an application framework for all layers: It offers a bean configuration foundation, AOP support, a JDBC abstraction framework, abstract transaction support, etc. It is a very non-intrusive effort: Your application classes do not need to depend on any Spring classes if not necessary, and you can reuse every part on its own if you like to. From its very design, the framework encourages clean separation of tiers, most importantly web tier and business logic: e.g. the validation framework does not depend on web controllers. Major goals are reusability and testability: Unnecessary container or framework dependencies can be considered avoidable evils.
Of course, Spring's own web support is nicely integrated with the framework's general patterns. Nevertheless, replacing the web solution with Struts, WebWork, or the like is easy. Both with Spring's web support or a different one, Spring allows for building a true dedicated middle tier in the web container, with the option to reuse exactly the same business logic in test environments or standalone applications. And within J2EE, your business logic will not unnecessarily depend on container services like JTA or EJB - allowing complex, well-architected web applications to run in a \container like Tomcat or Resin.
Note that Spring doesn't generally aim to compete with existing solutions. It rather fosters seamless integration with standards like Servlet, JSP, JTA, JNDI, JDBC, and JDO, and well-suited tools like Hibernate, Velocity, Log4J, and Caucho's Hessian/Burlap. The framework is designed to grow with the needs of your applications, in terms of technology choice: For example, you will probably use JTA