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 数据库驱动(DB Driver)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. 准备工具:MyEclipse 8.0 GA、Tomcat 6.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 /Add Struts Capabilities操作:修改struts类所在的包2.2.创建ActionForm 类操作:[打开struts的设计页面,右击] New/Form,Action,and JSP 类名:LoginForm在"Form Properties" 选项卡为loginForm 新增两个属性:username、password;2.3. 创建Action 类类名:LoginAction在“Parameter选项卡”中把Parameter的值设置成“methods”2.4. 创建jsp 文件index.jsp代码<%@page language="java"import="java.util.*"pageEncoding="UTF-8"%> <%response.sendRedirect(request.getContextPath()+"/login.jsp");%>login.jsp代码<%@page language="java"import="java.util.*"pageEncoding="UTF-8"%> <%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort() + path + "/";%><!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'login.jsp' starting page</title><meta http-equiv="pragma"content="no-cache"><meta http-equiv="cache-control"content="no-cache"><meta http-equiv="expires"content="0"><meta http-equiv="keywords"content="keyword1,keyword2,keyword3"><meta http-equiv="description"content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body>SSH框架搭建测试——登陆.<br><form action="<%=request.getContextPath()%>/login.do?methods=login"method="post"><input type="text"name="username"><br/><input type="password"name="password"><br/><input type="submit"value="登陆"><input type="button"value="注册"onclick="window.location.href='<%=request.getContextPath() %>/register.jsp'"> </form></body></html>Struts1.2+Spring2.5+Hibernate3.2框架搭建(二)register.jsp代码<%@page language="java"import="java.util.*"pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme() + "://"+ request.getServerName() + ":" + request.getServerPort()+ path + "/";%><!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><base href="<%=basePath%>"><title>My JSP 'register.jsp' starting page</title><meta http-equiv="pragma"content="no-cache"><meta http-equiv="cache-control"content="no-cache"><meta http-equiv="expires"content="0"><meta http-equiv="keywords"content="keyword1,keyword2,keyword3"><meta http-equiv="description"content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--></head><body>SSH框架搭建测试——注册.<br><form action="<%=request.getContextPath()%>/login.do?methods=register "method="post"><input type="text"name="username"><br/><input type="password"name="password"><br/><input type="submit"value="注册"><input type="button"value="返回"onclick="window.location.href='<%=request.getContextPath()%>/login.jsp'"> </form></body></html>2.5.修改Action类操作:添加login和register两个方法,其中register类先空着等添加完Hibernate之后在改写,login方法先为检测struts是否添加成功只在服务端检测用户为:zhoulukang 密码为:123的用户登陆。