Struts2.0+ibatis2.3整合实例实现UI层是什么呢?,让我们开始具体的步骤:
Struts2.0+ibatis2.3整合实例一:登录页面:login.jsp:
- ﹤%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%﹥
- ﹤%@ taglib uri="/struts-tags" prefix="s" %﹥
- ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥
- ﹤html﹥
- ﹤head﹥
- ﹤title﹥login.jsp﹤/title﹥
- ﹤/head﹥
- ﹤body﹥
- ﹤s:form action="logon.action" method="post"﹥
- ﹤s:textfield name="name" label="User Name:" /﹥
- ﹤s:password name="password" label="Password:" /﹥
- ﹤s:submit value="Submit" /﹥
- ﹤/s:form﹥
- ﹤/body﹥
- ﹤/html﹥
Struts2.0+ibatis2.3整合实例二:添加用户页面:addUser.jsp
- ﹤%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%﹥
- ﹤%@ taglib uri="/struts-tags" prefix="s" %﹥
- ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥
- ﹤html﹥
- ﹤head﹥
- ﹤title﹥addUser.jsp﹤/title﹥
- ﹤/head﹥
- ﹤body﹥
- ﹤s:form action="save.action" method="post"﹥
- ﹤s:textfield name="name" label="User Name:" /﹥
- ﹤s:password name="password" label="Password:" /﹥
- ﹤s:submit value="Save" /﹥
- ﹤/s:form﹥
- ﹤/body﹥
- ﹤/html﹥
Struts2.0+ibatis2.3整合实例三:显示用户列表页面:list.jsp
- ﹤%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%﹥
- ﹤%@ taglib uri="/struts-tags" prefix="s" %﹥
- ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥
- ﹤html﹥
- ﹤head﹥
- ﹤title﹥Users list﹤/title﹥
- ﹤style type="text/css"﹥
- table {
- border-collapse: collapse;
- }
- ﹤/style﹥
- ﹤/head﹥
- ﹤body﹥
- ﹤br /﹥﹤br /﹥﹤br /﹥﹤br /﹥
- ﹤table border="1" width="50%" align="center"﹥
- ﹤tr bgcolor="#cccc00"﹥
- ﹤td align="center"﹥UserId﹤/td﹥
- ﹤td align="center"﹥UserName﹤/td﹥
- ﹤td align="center"﹥Password﹤/td﹥
- ﹤td colspan="2" align="center"﹥Options﹤/td﹥
- ﹤/tr﹥
- ﹤s:iterator value="%{#request.list}" var="user"﹥
- ﹤tr﹥
- ﹤td align="center"﹥﹤s:property value="#user.id" /﹥﹤/td﹥
- ﹤td align="center"﹥﹤s:property value="#user.username" /﹥﹤/td﹥
- ﹤td align="center"﹥ ﹤s:property value="#user.password" /﹥﹤/td﹥
- ﹤td align="center"﹥﹤a href="update.action?id=﹤s:property value='#user.id' /﹥&action=loading" ﹥update﹤/a﹥﹤/td﹥
- ﹤td align="center"﹥﹤a href="delete.action?id=﹤s:property value='#user.id' /﹥" ﹥delete﹤/a﹥﹤/td﹥
- ﹤/tr﹥
- ﹤/s:iterator﹥
- ﹤/table﹥
- ﹤/body﹥
- ﹤/html﹥
Struts2.0+ibatis2.3整合实例四:更新用户页面:update.jsp
- ﹤%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%﹥
- ﹤%@ taglib uri="/struts-tags" prefix="s" %﹥
- ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥
- ﹤html﹥
- ﹤head﹥
- ﹤title﹥update.jsp﹤/title﹥
- ﹤/head﹥
- ﹤body﹥
- ﹤s:form action="update.action" method="post"﹥
- ﹤s:hidden name="id" value="%{#request.user.id}" /﹥
- ﹤s:textfield name="name" label="User Name:" value="%{#request.user.username}" /﹥
- ﹤s:password name="password" label="Password:" /﹥
- ﹤s:submit value="Update" /﹥
- ﹤/s:form﹥
- ﹤/body﹥
- ﹤/html﹥
Struts2.0+ibatis2.3整合实例五:一个成功页面:success.jsp
- ﹤%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%﹥
- ﹤%@ taglib uri="/struts-tags" prefix="s" %﹥
- ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥
- ﹤html﹥
- ﹤head﹥
- ﹤title﹥success﹤/title﹥
- ﹤/head﹥
- ﹤body﹥
- This is Success page. ﹤br﹥
- ﹤br /﹥﹤br /﹥
- ﹤a href="show.action"﹥显示用户列表﹤/a﹥ ﹤a href="addUser.jsp"﹥添加用户﹤/a﹥
- ﹤/body﹥
- ﹤/html﹥
Struts2.0+ibatis2.3整合实例七:失败页面:error.jsp
- ﹤%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%﹥
- ﹤!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"﹥
- ﹤html﹥
- ﹤head﹥
- ﹤title﹥error﹤/title﹥
- ﹤/head﹥
- ﹤body﹥
- This is Error page. ﹤br﹥
- ﹤/body﹥
- ﹤/html﹥
到此为止,我们整个项目就已经完成了,现在我们将整个项目打包成war包发布到Tomcat中测试:输入:
http://localhost:8080/addUser.jsp可以进行测试了。
演示示例下载地址:Struts2.0+Spring2.5.1+ibatis2.3地址:http://download.csdn.net/source/331581
Struts2.0+ibatis2.3整合实例实现服务层及Struts结构就向你讲解到这里,动手看看。【编辑推荐】