Spring+Struts2+Hibernate˶ʵ
ʹJSPWebҳ濪ԱʹHTMLXMLʶƺʽҳ档ʹJSPʶ߽űҳϵĶ̬ݡɶ̬ݵһ㱻װJavaBeanEJBJSPűСҳԱҳıԱͬСͬʱڿͻͨ鿴ԴļJSPʶ䣬JavaBeanEJBҲԱԴĴ롣
ServletԼ鼰ŵ
Servletһ֧JavaԵķϵͨJavaڷϡʹServletԺɵչJavaĹܣΪͻṩȫɿġֲĶ̬ҳ
ServletǸͻͻʱServletȡȻijServletServletִнظͻͻijԴʱServletʹServletRequestѿͻϢװȻJava Servlet APIжServletһЩڷServletִУŰServletִеҪظͻĽװServletResponseУServletѿͻͻΪͻһη̡Servletͼ1-1ʾ
request response Servlet Servlet 1 Servlet 2 Servlet 3 Web ͻ ͼ1-1 Servlet
Servletڣ
1.Чʣʹ߳ȡϵͳֹ̣ܹĿ̣߳ǰһʹòϵͳĽЧʸߡ
2.ǿṩݹӹ洢ܣǿĹʹǿʵԡ
3.ֲǿвϵͳUnixWindowsϵͳзϣTomcatWeblogicС
4.٣ڶѻշѵķѡʹõijɱ
5.ȫdzҲͶžʹתƷĹûл⡣ 6.ĿǰгϴֲƷʹøü
3
Spring+Struts2+Hibernate˶ʵ
Spring Լ鼰ŵ
SpringһԴܣRod JohnsonΪ˽ҵӦÿĸԶġSpringʹûJavaBeanǰֻEJBɵ顣ȻSpring;ڷ˵ĿӼԡɲԺϵĽǶȶԣκJavaӦöԴSpring档 ĿģҵӦÿĸ
ܣʹûJavaBeanEJBṩ˸ҵӦù ΧκJavaӦ
˵SpringһĿƷת(IOC)(AOP)ܡ
1.ӴС뿪SpringġSpringܿһСֻ1MBJARļSpringĴҲġ⣬SpringǷʽģ͵أSpringӦеĶSpringضࡣ 2. ƷתSpringͨһֳƷתIOCļٽϡӦIOCһͨķʽݽԼ߲ΪIOCJNDI෴Ƕвڶʼʱȶݸ
3. 桪Springṩ̵ķḻ֧֣ͨӦõҵϵͳƣauditingھԵĿӦöֻʵӦġҵ˶ѡDzʶϵͳע㣬־֧֡
4. SpringӦöúڣһÿbeanαһԭͣprototypebeanԴһʵÿҪʱһµʵԼġȻSpringӦñͬڴͳEJBǾӴ뱿صģʹá
5. ܡSpringԽáϳΪӵӦáSpringУӦöʽϣ͵һXMLļSpringҲṩ˺ܶܣ־ûܼɵȵȣӦĿ㡣
HibernateԼ鼰ŵ
Hibernateһݳ־òܣһʵֶϵ֮ӳ䣨O/R MappingĹߣJDBCĶװʹԱʹö˼ݿ⡣ṩ˴Javaൽݱӳ䣬ҲṩݲѯͻָơʹJDBCSQLݿ⣬ʹHibernateܴʵֵЧʡ
HibernateļʽJavaݱ֮ӳϵͬʱ
4
Spring+Struts2+Hibernate˶ʵ
IJ潫ݱ֮ĹϵΪJava֮ļ̳мȹϵͨʹHQL佫ӵĹϵ㷨öķʽں̶ܴϼ˶ݵIJѯӿ˿ЧʡHibernateһֱ۵APIڶݿʾĶִвѯҪЩֻڳǽнȻHibernate漴ɡװ־ûҵҪдJDBC䣬Ӷʹݳ־òõ˼ļ 1.2.2
MyEclipseߣÿEclipseһEclipseһܷdzǿĿߣMyEclipseڹTomcat˼ɣԶԶϡӺ̶ܴ˿ЧʣԼ˿ʱ䡣
MyEclipseṩ˶Զƽ̨Ե֧֡߿ʹǸоʡϤƽ̨WindowsLinuxȡEclipseÿƽ̨䵥ͼι߰ʹӦóнӽزϵͳۺõܡ 1.2.3
Struts2ʵMVCܹMVCModel-View-ControllerTrygve ReenskaugȱӦSmallTalk-80УཻͽϵͳĹɻݽƿɱԵMVCѽϵͳɷֽģ͡ͼ֡[6]
ģͣModelڶʾݺʽµڳװĺݡܵļϵھĽI/OͼViewѱʾģݼϵ״̬ϢضʽչʾûģͻʾϢͬϢжͬʾʽͼControllerǴûĽģְǿṩģκα仯ĴȷûģͼĶӦϵû룬뷴ģͣʵֶģ͵ļƣʹģͺͼЭIJͨһͼӦһģ͡ͼķ룬ʹһģͿԾжʾͼûͨijͼĿıģ͵ݣЩݵͼӦӳЩ仯ˣ ʱ˺ݱ仯Ὣ仯֪ͨеͼʾĸ¡ʵһģ͵ı仯ơ
Struts2StrutsWebWorkĹͬɹ˵Struts2WebWork棬õWebWorkĺģԣStruts2һIJƷ෴WebWork֮ϵStruts2һȶ졢ƳWEBܡ
һStruts2еĴŷΪ¼裺
5
Spring+Struts2+Hibernate˶ʵ
1ͻ˳ʼһָServletTomcat
2һϵеĹFilterЩһActionContextCleanUpĿѡStruts2ܵļɺа磺SiteMesh Plugin
3FilterDispatcherãFilterDispatcherѯActionMapperǷҪijAction
4ActionMapperҪijActionFilterDispatcherĴActionProxy
5ActionProxyͨConfiguration ManagerѯʿܵļҵҪõActionࣻ
6ActionProxyһActionInvocationʵ
7ActionInvocationʵʹģʽãڵActionĹǰ漰Intercepterĵá
8һActionִϣActionInvocationstruts.xmlеҵӦķؽؽͨǣǣҲһActionһҪʾJSPFreeMarkerģ档ڱʾĹпʹStruts2м̳еıǩҪ漰ActionMapper
1.2.4 SSH(Spring Struts2 Hibernate)ϵŵ㣺
͵J2EEṹΪֲ㡢м㣨ҵ㣩ݷ㡣ϵҵݷʼϷУȹм㴦ͻ˲ֱݿ⽻ͨм㽨ӣмݿ⽻
ֲǴͳJSP1999ķչ㷺Ӧúȶı֣ΪΪֲ㼼˼ʵĻ
мõеSpring+HibernateΪ˽Ʋҵ룬ϸΪ¼֡
Web㣬MVCģʽġCcontrollerҵֲĽҵ㣬ҵݷظֲ֣֯ϵͳMVCܲStruts
Service㣨ҵ㣩ʵҵҵDAOΪͨDAOģʽװϵͳҪҵ
DAO㣬־ûòװݵɾ顢ĵIJ PO־ûͨʵϵӳ乤߽ϵݿӳɶܷʵʽݿ⣬ϵͳHibernateΪORMܡ
Springùᴩм㣬Web㡢Service㡢DAO㼰POϣ
6