Spring+Struts2+Hibernate的运动社区的设计与实?- 百度文库

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

ϵͷ779662525#qq.com(#滻Ϊ@)