SSH2配置完整案例一新建WEB项目SSH2二在dbbrowser中新建数据连接sql三添加struts2容器四添加spring容器五添加hibernate容器这里应当是webroot/web-inf/applicationContext.xml完成后结构图如下:六配置各文件1配置struts.xml?xmlversion=1.0encoding=UTF-8?!DOCTYPEstrutsPUBLIC-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.1//EN!--开发模式--constantname=struts.devModevalue=true/!--告诉struts2,action的创建交给spring--constantname=struts.ObjectFactoryvalue=spring/constantpackagename=struts2extends=struts-defaultactionname=listclass=com.my.action.ListAdminresultname=successlistAdmin.jsp/result/action/package/struts2配置web.xmllistenerlistener-classorg.springframework.web.context.ContextLoaderListener/listener-class/listenerfilterfilter-namestruts2/filter-namefilter-classorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter/filter-class/filterfilter-mappingfilter-namestruts2/filter-nameurl-pattern/*/url-pattern/filter-mapping7代码1逆向工程admin表生成后的结构2ListAdmin.javaaction类packagecom.my.action;importjava.util.List;importcom.my.orm.Admin;importcom.my.orm.AdminDAO;importcom.opensymphony.xwork2.ActionSupport;publicclassListAdminextendsActionSupport{AdminDAOadminDAO;ListAdminlist;@OverridepublicStringexecute()throwsException{list=adminDAO.findAll();returnsuccess;}publicAdminDAOgetAdminDAO(){returnadminDAO;}publicvoidsetAdminDAO(AdminDAOadminDAO){this.adminDAO=adminDAO;}publicListAdmingetList(){returnlist;}publicvoidsetList(ListAdminlist){this.list=list;}}3listAdmin.jsp%@pagelanguage=javaimport=java.util.*pageEncoding=utf-8%%@taglibprefix=suri=/struts-tags%%@taglibprefix=curi=!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlbodytableborder=1trtdAPass/tdtdAHeader/tdtdAPhone/tdtdAEmail/tdc:forEachitems=${list}var=xtrtd${x.AName}/tdtd${x.AHeader}/tdtd${x.APhone}/tdtd${x.AEmail}/td/td/c:forEach/table/body/html4strut.xml配置packagename=struts2extends=struts-defaultactionname=listclass=com.my.action.ListAdminresultname=successlistAdmin.jsp/result/action/package5applicationContext.xml中自动生成的id=”AdminDAO”修改成id=”adminDao”(也就是AdminDao第一个字母小写,使之与ListAdmin.java中属性adminDAO相匹配)beanid=adminDAOclass=com.my.orm.AdminDAOpropertyname=sessionFactoryrefbean=sessionFactory//property/bean最后部署并运行