您好,欢迎访问三七文档
Struts1.2+Spring2.5+Hibernate3.2框架搭建(一)1.准备1.1.创建工程1.2.在工程中建包2.Struts部分2.1.添加Struts功能支持2.2.创建ActionForm类2.3.创建Action类2.4.创建jsp文件2.5.修改Action类2.6.测试struts框架3.Spring部分3.1.添加Spring功能支持3.2.配置web.xml文件3.3.配置struts-config.xml文件3.4.修改Spring配置文件applicationContext.xml3.5.增加log4j日志功能3.6.测试4.Hibernate部分4.1.创建sqlserver2000数据库和表4.2.创建MyEclipse数据库驱动(DBDriver)4.3.添加Hibernate功能支持4.4.创建对象关系映射(ORM)的相关文件4.5.创建数据层:IUsersDAO.java接口和UsersDAOImpl.java类,业务层:IUsersBusiness.java接口和UsersBusinessImpl.java类。4.6.修改LoginAction.java文件4.7.修改Spring配制文件applicationContext.xml4.8.测试Struts1.2+Spring2.5+Hibernate3.2框架搭建1.准备工具:MyEclipse8.0GA、Tomcat6.0环境:Struts1.2、Spring2.5、Hibernate3.2、sqlserver20001.1.创建工程1.2.在工程中建包com.zlk.business业务层接口类com.zlk.business.impl业务层实现类com.zlk.dao数据层接口类com.zlk.dao.impl数据层实现类com.struts.action控制层com.struts.form2.Struts部分2.1.添加Struts功能支持操作:[右击项目]MyEclipse/AddStrutsCapabilities操作:修改struts类所在的包2.2.创建ActionForm类操作:[打开struts的设计页面,右击]New/Form,Action,andJSP类名:LoginForm在FormProperties选项卡为loginForm新增两个属性:username、password;2.3.创建Action类类名:LoginAction在“Parameter选项卡”中把Parameter的值设置成“methods”2.4.创建jsp文件index.jsp代码%@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%%response.sendRedirect(request.getContextPath()+/login.jsp);%login.jsp代码%@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'login.jsp'startingpage/titlemetahttp-equiv=pragmacontent=no-cachemetahttp-equiv=cache-controlcontent=no-cachemetahttp-equiv=expirescontent=0metahttp-equiv=keywordscontent=keyword1,keyword2,keyword3metahttp-equiv=descriptioncontent=Thisismypage!--linkrel=stylesheettype=text/csshref=styles.css--/headbodySSH框架搭建测试——登陆.brformaction=%=request.getContextPath()%/login.do?methods=loginmethod=postinputtype=textname=usernamebr/inputtype=passwordname=passwordbr/inputtype=submitvalue=登陆inputtype=buttonvalue=注册onclick=window.location.href='%=request.getContextPath()%/register.jsp'/form/body/htmlStruts1.2+Spring2.5+Hibernate3.2框架搭建(二)register.jsp代码%@pagelanguage=javaimport=java.util.*pageEncoding=UTF-8%%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+://+request.getServerName()+:+request.getServerPort()+path+/;%!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML4.01Transitional//ENhtmlheadbasehref=%=basePath%titleMyJSP'register.jsp'startingpage/titlemetahttp-equiv=pragmacontent=no-cachemetahttp-equiv=cache-controlcontent=no-cachemetahttp-equiv=expirescontent=0metahttp-equiv=keywordscontent=keyword1,keyword2,keyword3metahttp-equiv=descriptioncontent=Thisismypage!--linkrel=stylesheettype=text/csshref=styles.css--/headbodySSH框架搭建测试——注册.brformaction=%=request.getContextPath()%/login.do?methods=registermethod=postinputtype=textname=usernamebr/inputtype=passwordname=passwordbr/inputtype=submitvalue=注册inputtype=buttonvalue=返回onclick=window.location.href='%=request.getContextPath()%/login.jsp'/form/body/html2.5.修改Action类操作:添加login和register两个方法,其中register类先空着等添加完Hibernate之后在改写,login方法先为检测struts是否添加成功只在服务端检测用户为:zhoulukang密码为:123的用户登陆。/**GeneratedbyMyEclipseStruts*Templatepath:templates/java/JavaClass.vtl*/packagecom.zlk.struts.action;importjava.io.IOException;importjava.io.PrintWriter;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importorg.apache.struts.action.ActionForm;importorg.apache.struts.action.ActionForward;importorg.apache.struts.action.ActionMapping;importorg.apache.struts.actions.DispatchAction;importcom.zlk.struts.form.LoginForm;/***MyEclipseStruts*Creationdate:03-05-2010**XDocletdefinition:*@struts.actionpath=/loginname=loginFormparameter=methodsscope=requestvalidate=true*/publicclassLoginActionextendsDispatchAction{/**GeneratedMethods*//***登陆的方法*/publicActionForwardlogin(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){LoginFormloginForm=(LoginForm)form;//TODOAuto-generatedmethodstubresponse.setContentType(text/html;charset=UTF-8);PrintWriterout=null;try{out=response.getWriter();if(loginForm.getUsername().equals(zhoulukang)&&loginForm.getPassword().equals(123)){out.print(fontcolor='red'+loginForm.getUsername()+/font恭喜你登陆成功!);}else{out.println(对不起,登陆失败);}}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}returnnull;}/***注册的方法*/publicActionForwardregister(ActionMappingmapping,ActionFormform,HttpServletRequestrequest,HttpServletResponseresponse){LoginFormloginForm=(LoginForm)form;//TODOAuto-generatedmethodstubreturnnull;}}2.6.测试struts框架操作:输入用户名密码操作:点击登陆Struts1.2+Spring2.5+Hibernate3.2框架搭建(三)3.Spring部分3.1.添加Spring功能支持操作:[右击项目]MyEclipse/AddSpringCapabilities开发包选择:Spring2.5AOPLibraries、Spring2.5CoreLibraries、Spring2.5PersistenceCoreLibraries、Spring2.5PersistenceJDBCLibraries、Spring2.5WebLibrariesJAR
本文标题:ssh框架整合搭建
链接地址:https://www.777doc.com/doc-4992986 .html