接着前面的讲解,我们现在开始做UI层:
登录页面: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 >
<% @ 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 >
<%
@ 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 >
<% @ 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 >
<%
@ 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 >
<% @ 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 >
<%
@ 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 >
<% @ 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 >
<%
@ 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 >
<% @ 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 >
<%
@ 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 >
<! 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.0+Hibernate3.1登录及增删改查的完整演示示例下载地址:http://download.csdn.net/source/326113
以前的一个版本:Struts1.2+Spring1.2+HIbernate3.1整合登录示例示例:http://download.csdn.net/source/323772
如果大家在做这个项目中有任何问题请给我留言,我抽出时间给你们予以回复。谢谢大家!