Struts2.0+Spring2.0+Hibernate3.1登录及增删改查的完整演示示例 连载中...(四)

18 篇文章 0 订阅

接着前面的讲解,我们现在开始做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 >
添加用户页面: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 >
显示用户列表页面: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" > &nbsp; < s:property  value ="#user.password"   /></ td >
            
< td  align ="center" >< href ="update.action?id=<s:property value='#user.id' />&action=loading"   > update </ a ></ td >
            
< td  align ="center" >< href ="delete.action?id=<s:property value='#user.id' />"   > delete </ a ></ td >
        
</ tr >
        
</ s:iterator >
    
</ table >
  
</ body >
</ html >
更新用户页面: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 >
下面就是一个成功页面: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  />
    
< href ="show.action" > 显示用户列表 </ a >    < href ="addUser.jsp" > 添加用户 </ a >
  
</ body >
</ html >
最后一个就是失败页面: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.0+Hibernate3.1登录及增删改查的完整演示示例下载地址:http://download.csdn.net/source/326113

  以前的一个版本:Struts1.2+Spring1.2+HIbernate3.1整合登录示例示例:http://download.csdn.net/source/323772

如果大家在做这个项目中有任何问题请给我留言,我抽出时间给你们予以回复。谢谢大家!

评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值