资源描述:
《freemarker在struts218,java,web中的应用实例》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、FreeMarker在struts2.1.&JAVA,web中的应用实例FreeMarker,sapplicationexampleinstruts2・1.8,JAVA,web,2010-05-0700:32FreeMarkeroverviewFreeMarkerisatemplatingengine,agenerictoolforgeneratingtextoutputbasedontemplates,writteninplainJavaTemplate+datamodel=outputFreeMarkerisaverygoodtemplateengine,thet
2、emplateenginecanbeusedinanyscene,FreeMarkerwillberesponsibleforthedatamodelofdatamergingintothetemplate,therebygeneratingastandsrdoutput・Theinterfacedevelopersonlyneedtopayattentiontotheinterface(i.e.templatefile)andthebusinesslogicdevelopment,developersonlyneedtoresponsibleforthedispla
3、yofdatafillinthedatamodelofFreeMarkerisresponsibleformergingdatamodelandtemplatetogeneratestandardoutput・TheapplicationofWebFreeMarkerisparticularlysuitableforMVCmode,althoughFreeMarkerhassomeprogrammingskills,buttheprogrammingabilityisverylimited,notrealizingthebusinesslogic,canonlypro
4、videsomedataformatconversionfunction.Therefore,usuallybytheJavaprogramtodisplaythedatabytheFreeMarkertemplateenginetogeneratetheFreeMarkerpage,andprovidespagetemplatethelayoutofsupport.(benefits:strictimplementationofMVCseparation)Inaddition,FreeMarkeralsohasnothingtodowiththeWebcontain
5、er,whichisFreeMarkerdoesnotnecessarilyneedtoruninlheWebcontainer:FreeMarkercanalsobeappliedtononWebapplicationenvironment・Moreover,FreeMarkernotonlygenerateHTMLpages,itcanalsogenerateavarietyoftext,suchasXML,RTF,Javasourcecode・Struts2defaultstousingFreeMarkerasitstemplatefile,whileallof
6、theStruts2themetemplatefilesarewritteninFreeMarker,andJSP,Java,andothertemplatefilesineclipsearealsousingFreeMarkerTechnologyFirst,useFreeMarkerinStruts2Withasimpleadduserinformationforexample:whentheuserclicksonthefrontpageofthe"adduser"connection,thensendsarequesttoaddauserpage(addinp
7、ut・action),andthenwereturnapage,hereisourcommonStruts2configurationfileissoconfigured:/addlnput・jsp〈/result〉Addinput.jspfile:<%@pagelanguage^〃Java〃import二java.util.*"pageEncoding=〃IS0-8859-1〃%