一个Java小例子(通过Radio进行选中查询)

页面1的head部分

< script language = " JavaScript " >
   function t_kinntai_monthDisp() 
{
    document.forms[
0].action = "t_kinntai_monthDisp.do" ;
    document.forms[
0].submit() ;
   }

   function t_kinntaiDisp() 
{
    document.forms[
0].action = "t_kinntaiDisp.do" ;
    document.forms[
0].submit() ;
   }

</ script >
页面1的body部分
<%    // 年是以下拉列表显示,列表中有系统当前年份和之前的两个年份.
  java.text.SimpleDateFormat simpleDate = new  java.text.SimpleDateFormat( " yyyy " ) ;
  java.util.Date date
= new  java.util.Date() ;
  String strTime
= simpleDate.format(date) ;
  
int  i = 2 ;
%>
  年:
< SELECT  >
<%
  
while (i >= 0 ) {
  String ss
=String.valueOf(Integer.parseInt(strTime)-i);
%>
    
<option value="<%=ss%>" selected><%=ss%></option>
<%i--;}
%>
  
</ SELECT >
  员工卡号:
< html:text property = " syain_cd "  size = " 10 "  maxlength = " 4 " />
  
< input type = " submit "  value = "  搜 索  "  onclick = " t_kinntai_monthDisp() " >
<%   
      // 定义变量ss用以取得t_kinntai_monthForm中Visbale的值,来控制明细按钮和table是否显示.
  form.attendance.T_kinntai_monthForm t_kinntai_monthForm  =  
      (form.attendance.T_kinntai_monthForm)session.getAttribute(
" T_kinntai_monthForm " ) ;
  String ss
= t_kinntai_monthForm.getVisbale();
%>
  
< input type = " submit "  value = "  明 细  "  style = " <%=ss%> "  onclick = " t_kinntaiDisp() " >
< table border = " 1 "  CellSpacing = " 0 "  cellpadding = " 0 "  width = " 100% "  style = " <%=ss%> " >
  
< tr >
    
< td width = 30  height = 50 >& nbsp; </ td >
    
< td align = " center " > 考勤月份 </ td >
    
< td align = " center "  width = 100 > 确认情况 </ td >  
  
</ tr >
  
< tr >
    
< logic:notEmpty n ame = " T_kinntai_monthForm "  scope = " session "  property = " t_kinntai_monthList " >
    
< logic:iterate id = " t_kinntai_monthInfList "  property = " t_kinntai_monthList "  
           n ame
= " T_kinntai_monthForm "  scope = " session "  indexId = " index " >
    
<%  String radioCount  =  String.valueOf(index) ; %>
    
< td >
      
< html:radio name = " T_kinntai_monthForm "  property = " selIndex "  value = " <%=radioCount%> " />
    
</ td >
    
< td >< bean:write name = " t_kinntai_monthInfList "  property = " kinntai_m " />& nbsp; </ td >
    
< logic:equal name = " t_kinntai_monthInfList "  property = " kakuninn_jyoutai "  value = " 0 " >
      
< td > 已确认 </ td >  
    
</ logic:equal >
    
< logic:equal name = " t_kinntai_monthInfList "  property = " kakuninn_jyoutai "  value = " 1 " >
      
< td > 未确认 </ td >  
    
</ logic:equal >
  
</ tr >
  
</ logic:iterate >  
  
</ logic:notEmpty >
</ table >
Struts-config.xml部分
<!-- Oracle连接部分 -->
< data-sources  >
    
< data-source  key ="Access" >
      
< set-property  property ="password"  value ="tuosi"   />
      
< set-property  property ="minCount"  value ="5"   />
      
< set-property  property ="maxCount"  value ="100"   />
      
< set-property  property ="user"  value ="tuosi"   />
      
< set-property  property ="driverClass"  value ="oracle.jdbc.driver.OracleDriver"   />
      
< set-property  property ="url"  value ="jdbc:oracle:thin:@localhost:1521:database"   />
      
< set-property  property ="autoCommit"  value ="true"   />
    
</ data-source >
</ data-sources >  

< form-beans  >
 
< form-bean  name ="T_kinntai_monthForm"  type ="form.attendance.T_kinntai_monthForm"   />
 
< form-bean  name ="T_kinntaiForm"  type ="form.attendance.T_kinntaiForm"   />
</ form-beans >  

< action  path ="/t_kinntai_monthFind"  
       type
="action.attendance.T_kinntai_monthAction"  
       validate
="false"  
       name
="T_kinntai_monthForm"  
       scope
="session"  
       parameter
="init" >
  
< forward  name ="forward"  path ="/jsp/t_kinntai_month.jsp" />  
 
</ action >  
    
 
< action  path ="/t_kinntai_monthDisp"  
       type
="action.attendance.T_kinntai_monthAction"  
       validate
="false"  
       name
="T_kinntai_monthForm"  
       scope
="session"  
       parameter
="disp" >
  
< forward  name ="forward"  path ="/jsp/t_kinntai_month.jsp" />  
 
</ action >   

 
< action  path ="/t_kinntaiDisp"  
   type
="action.attendance.T_kinntaiAction"  
   validate
="false"  
   name
="T_kinntaiForm"  
   scope
="session"  
   parameter
="disp" >
  
< forward  name ="forward"  path ="/jsp/t_kinntai.jsp" />  
 
</ action >    

<!-- 表单验证 -->
< message-resources  parameter ="message.ApplicationResources"   />
Action1的ActionForward部分
public  ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,
         HttpServletResponse response)
throws  Exception {
  ActionForward actionForward 
= new ActionForward();
  
/*一覧画面初期処理 */
  
if (mapping.getParameter().equals( "init" ) ) {
   actionForward 
= doInit( mapping, form, request, response ) ;
  }
 else if (mapping.getParameter().equals( "disp" ) ) {
   actionForward 
= doDisp( mapping, form, request, response ) ; }
 
  
return actionForward ; }
Action1的Init部分
private  ActionForward doInit(ActionMapping mapping,ActionForm form,HttpServletRequest request,
                HttpServletResponse response ) 
throws  Exception  {

//初始化时用以控制是否显示.(display:none为不显示,display为显示)
  T_kinntai_monthForm t_kinntai_monthForm = (T_kinntai_monthForm) form ;
  t_kinntai_monthForm.setVisbale( 
"display:none" ) ;
  
return mapping.findForward( "forward" ) ;}
Action1的Disp部分
private  ActionForward doDisp(ActionMapping mapping,ActionForm form,HttpServletRequest request,
                HttpServletResponse response ) 
throws  Exception  {

//创建T_kinntai_monthForm的对象t_kinntai_monthForm .
  T_kinntai_monthForm t_kinntai_monthForm = ( T_kinntai_monthForm ) form ;

//创建T_kinntai_monthAccess 的对象t_kinntai_monthAccess.
  T_kinntai_monthAccess t_kinntai_monthAccess = new T_kinntai_monthAccess() ;

创建T_kinntai_monthInf的对象t_kinntai_monthList .
  T_kinntai_monthInf[] t_kinntai_monthList 
= null ;
//DateSource設定
  DataSource ds = this.getDataSource( request, "Access") ;
//Connection値設定
  Connection conn = null ;
  
try {
//创建表单验证对象errors.
    ActionErrors errors = new ActionErrors() ;
//社員コードがヌルかどうかを判断する
    if(t_kinntai_monthForm.getSyain_cd()==null || 
       t_kinntai_monthForm.getSyain_cd().trim().equals(
"") ) {
//エラーメッセージを追加する
      errors.add( "syain_cdIsNull"new ActionError( "ER001" ) ) ;         }

//社員コードが4桁以下かどうか判断する
    else if ( t_kinntai_monthForm.getSyain_cd().length() != 4 ) {
//エラーメッセージを追加する
      errors.add( "syain_cdLenth"new ActionError ( "ER003" ) ) ; }

//社員コードが数字かどうかを判断する
    else {
    
try {
      Integer.parseInt( t_kinntai_monthForm.getSyain_cd().trim() ) ; 
    }
catch ( Exception e ) {
//エラーメッセージを追加する
      errors.add( "syain_cdIsNotInteger",new ActionError( "ER003" ) ) ;}
}

//エラーメッセージをセーブ
  saveErrors( request, errors ) ;
//创建连接
   conn = ds.getConnection() ;
   
int kinntai_y = Integer.parseInt( request.getParameter( "kinntai_yList" ) ) ;
   t_kinntai_monthForm.setKinntai_y( kinntai_y ) ;
   String syain_cd 
= t_kinntai_monthForm.getSyain_cd( );
//获得t_kinntai_monthAccess中的方法getT_kinntai_monthInf()返回的t_kinntai_monthList值.
   t_kinntai_monthList = t_kinntai_monthAccess.getT_kinntai_monthInf( conn, kinntai_y, syain_cd ) ;
//将t_kinntai_monthList赋予Session.
   request.getSession().setAttribute( "t_kinntai_monthList", t_kinntai_monthList ) ;
//Visbale值为display是显示状态
   t_kinntai_monthForm.setVisbale( "display" ) ;
//判断t_kinntai_monthList是否有值
   if ( t_kinntai_monthList == null || t_kinntai_monthList.length == 0 ){
    t_kinntai_monthForm.setT_kinntai_monthList( 
null ) ;
   }
 else {
//第一项为选中,并将t_kinntai_monthList赋予Form中的T_kinntai_monthList
    t_kinntai_monthForm.setSelIndex( "0" ) ;
    t_kinntai_monthForm.setT_kinntai_monthList( t_kinntai_monthList ) ;}

  }
 catch ( Exception ex ) {
   ex.printStackTrace() ;  }

  
return mapping.findForward( "forward" ); }
t_kinntai_monthAccess的getT_kinntai_monthInf部分
public  T_kinntai_monthInf[] getT_kinntai_monthInf( 

            Connection conn, 
int  kinntai_y, String syain_cd )  {
  T_kinntai_monthInf[] t_kinntai_monthList 
= null ;
  ArrayList  t_kinntai_monthInfArray 
= null ;
  PreparedStatement pstmt 
= null ;
  ResultSet rs 
= null ;
     
try{
      t_kinntai_monthInfArray 
= new ArrayList() ;
// SQL
      String sql = "select SYAIN_CD, KINNTAI_Y, KINNTAI_M, SOUSIGOTO_JIKANN" ;
      sql 
+=  ",SIYOU_JIKANN, BYOUKI_JIKANN, KADAIKYUU_JIKANN, DAIKYUU_JIKANN" ;
      sql 
+= ",ZANNYO_DAIKYUU_JIKANN, NENNKYUU_JIKANN, NENNKYUU_HYOUJYUNN_JIKANN" ;
      sql 
+=  ",ZANNYO_NENNKYUU_JIKANN, HEIJITU_JIKANN, YORU_JIKANN, KYUUJITU_JIKANN" ;
      sql 
+=  ",SETINITI_JIKANN, KEKKINN_JISUU, KAKUNINN_JYOUTAI" ;    
      sql 
+= " from T_KINNTAI_MONTH where KINNTAI_Y="+kinntai_y+" and SYAIN_CD='"+syain_cd+"'" ;
      pstmt 
= conn.prepareStatement( sql ) ;
// 実行する
      rs = pstmt.executeQuery() ;
      
while( rs.next() ) {
      T_kinntai_monthInf t_kinntai_monthInf 
= new T_kinntai_monthInf() ;
      
// 社員コード
      t_kinntai_monthInf.setSyain_cd( rs.getString( "SYAIN_CD" ) ) ;
      
// 勤怠年
      t_kinntai_monthInf.setKinntai_y( rs.getInt( "KINNTAI_Y" ) ) ; 
      
// 確認状態
      t_kinntai_monthInf.setKakuninn_jyoutai( rs.getString( "KAKUNINN_JYOUTAI" ) ) ;
      t_kinntai_monthInfArray.add( t_kinntai_monthInf ) ;
      }

         t_kinntai_monthList 
= new T_kinntai_monthInf[ t_kinntai_monthInfArray.size() ] ;
         t_kinntai_monthInfArray.toArray( t_kinntai_monthList ) ;
         rs.close() ;
         pstmt.close() ;
         conn.close() ;      }

     
catch(Exception ex){       
      ex.printStackTrace() ;   }

   
return t_kinntai_monthList ;    }

 

页面2的head部分

< script language = " JavaScript " >
   
function  t_kinntai_monthDisp()  {
    document.forms[
0].action = "t_kinntai_monthFind.do" ;
    document.forms[
0].submit() ;
   }

</ script >
页面2的body部分
< form action = " t_kinntai_monthFind.do " >
  年:
< bean:write property = " kinntai_y " />
  员工卡号:
< bean:write property = " syain_cd " />
  
< input type = " submit "  value = "  返 回  "   >
  
< div style = " width:100%;height:550;overflow-x:scroll;overflow-y:scroll " >
  
< table border = " 1 "  CellSpacing = " 0 "  cellpadding = " 0 "  width = " 100% " >
    
< tr >
      
< td align = " center " > 日期 </ td >
      
< td align = " center " > 上班时间 </ td >
      
< td align = " center " > 确认情况 </ td >
    
</ tr >
    
< tr >
    
< logic:notEmpty scope = " session "  property = " t_kinntaiList " >
    
< logic:iterate property = " t_kinntaiList "  scope = " session "  indexId = " index " >
      
< td bgcolor = " <bean:write n ame= " t_kinntaiInfList "  property= " saikinntai_flag " /> " >
        
< bean:write n ame = " t_kinntaiInfList "  property = " kinntai_ymd " />& nbsp;
      
</ td >
      
< td bgcolor = " <bean:write property= " saikinntai_flag " /> " >
        
< bean:write n ame = " t_kinntaiInfList "  property = " syukkinn_jikoku " />& nbsp;
      
</ td >
      
< logic:equal property = " zanngyou_jyoutai "  value = " 0 " >
        
< td bgcolor = " <bean:write n ame= " t_kinntaiInfList "  property= " saikinntai_flag " /> " >
          已确认
        
</ td >  
      
</ logic:equal >
      
< logic:equal property = " zanngyou_jyoutai "  value = " 1 " >
        
< td bgcolor = " <bean:write n ame= " t_kinntaiInfList "  property= " saikinntai_flag " /> " >
          一级未确认
        
</ td >  
      
</ logic:equal >
      
< logic:equal property = " zanngyou_jyoutai "  value = " 2 " >
        
< td bgcolor = " <bean:write n ame= " t_kinntaiInfList "  property= " saikinntai_flag " /> " >
          二级未确认
        
</ td >  
      
</ logic:equal >
    
</ tr >
    
</ logic:iterate >  
    
</ logic:notEmpty >
  
</ table >
</ form >
Action2的execute部分
public  ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request,
          HttpServletResponse response ) 
throws  Exception  {
  ActionForward actionForward 
= new ActionForward() ;
  
/*一覧画面初期処理 */
  
if ( mapping.getParameter().equals( "disp" ) ) {
   actionForward 
= doDisp( mapping, form, request, response ) ;  }

  
return actionForward ; }
Action2的Disp部分
private  ActionForward doDisp(ActionMapping mapping,ActionForm form,HttpServletRequest request,
           HttpServletResponse response ) 
throws  Exception  {
  T_kinntaiForm t_kinntaiForm 
= ( T_kinntaiForm ) form ;
  T_kinntaiAccess t_kinntaiAccess 
= new T_kinntaiAccess() ;
//通过Session取得t_kinntai_monthList
  T_kinntai_monthInf[] t_kinntai_monthList = ( T_kinntai_monthInf[] ) request.getSession().getAttribute( "t_kinntai_monthList" ) ;
  T_kinntaiInf[] t_kinntaiList 
= null ;
  DataSource ds 
= this.getDataSource( request, "Access" ) ;
        
//Connection値設定
  Connection conn = null ;
  
try {
   conn 
= ds.getConnection() ;
//定义变量kinntai_ym用以获得页面选择的时间.
   String kinntai_ym = request.getParameter( "kinntai_yList" ) ;
//通过下面的方法取得t_kinntai_monthList中对应选中的月份*****
   int Kinntai_m = t_kinntai_monthList[ Integer.parseInt( t_kinntaiForm.getSelIndex() ) ].getKinntai_m() ;
//因库中日期字段为Number,所以当月份为1~9时为单数,可补零.
   if ( Integer.toString( Kinntai_m ).trim().length() == 1 ) {
    kinntai_ym 
+= "0" + Kinntai_m ;   }

   
else {    
    kinntai_ym 
+= Kinntai_m ;   }

//定义变量取得页面输入员工CD号.
   String syain_cd = request.getParameter( "kinntai_cd" ) ;
//将数据库连接,日期,员工CD号传给t_kinntaiAccess中的方法getT_kinntaiInf()用以取得返回的t_kinntaiList
   t_kinntaiList = t_kinntaiAccess.getT_kinntaiInf( conn,kinntai_ym, syain_cd ) ; 
   
if ( t_kinntaiList == null || t_kinntaiList.length == 0 ) {
    t_kinntaiForm.setT_kinntaiList( 
null ) ;   }
 
   
else {    
    t_kinntaiForm.setT_kinntaiList( t_kinntaiList ) ;   }

  }
 catch( Exception ex ) {
   ex.printStackTrace();
  }

  
return mapping.findForward( "forward" ) ; }
t_kinntaiAccess的getT_kinntaiInf部分
public  T_kinntaiInf[] getT_kinntaiInf( Connection conn, String kinntai_ymd, String syain_cd )  {
     T_kinntaiInf[] T_kinntaiList 
= null ;
     ArrayList  T_kinntaiInfArray 
= null ;
     PreparedStatement pstmt 
= null ;
     ResultSet rs 
= null ;
     
try {      
   T_kinntaiInfArray 
= new ArrayList() ;   
//SQL
   String sql = "select SYAIN_CD, KINNTAI_YMD, SYURUI, SYUKKINN_JIKOKU, TAIKINN_JIKOKU" ;
      sql 
+=  ", BYOUKI_JIKANN + SIYOU_JIKANN + DAIKYUU_JIKANN + NENNKYUU_JIKANN as leave, HEIJITU_JIKANN" ;
      sql 
+= " + YORU_JIKANN + KYUUJITU_JIKANN + SETINITI_JIKANN as overtime, GOUKEI_JIKANN, TIKOKU_FLAG" ;
      sql 
+=  ", SOUTAI_FLAG, SAIKINNTAI_FLAG, KAKUNINNSYA_ONE, KAKUNINNSYA_TWO, ZANNGYOU_JYOUTAI" ;
      sql 
+= " from T_KINNTAI" ;
      sql 
+= " where kinntai_ymd like '%"+ kinntai_ymd +"%' and SYAIN_CD='"+ syain_cd +"'";
   pstmt 
= conn.prepareStatement(sql) ;
   
//実行する
   rs = pstmt.executeQuery() ;
   
while( rs.next() ) {
    T_kinntaiInf t_kinntaiInf 
= new T_kinntaiInf() ;
    
// 社員コード
    t_kinntaiInf.setSyain_cd( rs.getString( "SYAIN_CD" ) ) ;
    
// 勤怠日付(年月日)
    t_kinntaiInf.setKinntai_ymd( rs.getString( "KINNTAI_YMD" ) ) ;
    
// 再勤怠フラグ
    if ( rs.getString( "SAIKINNTAI_FLAG" ).trim().equals( "1" ) ) {
     t_kinntaiInf.setSaikinntai_flag( 
"#CCCCCC" ) ;    }

    
else {     
     t_kinntaiInf.setSaikinntai_flag( 
"" ) ;    }

    
// 一級確認者
    t_kinntaiInf.setKakuninnsya_one( rs.getString( "KAKUNINNSYA_ONE" ) ) ; 
    
// 二級確認者
    t_kinntaiInf.setKakuninnsya_two( rs.getString( "KAKUNINNSYA_TWO" ) ) ;
    
// 確認状態
    t_kinntaiInf.setZanngyou_jyoutai( rs.getString( "ZANNGYOU_JYOUTAI" ) ) ;
    T_kinntaiInfArray.add( t_kinntaiInf ) ;   }

    T_kinntaiList 
= new T_kinntaiInf[ T_kinntaiInfArray.size() ] ;
    T_kinntaiInfArray.toArray( T_kinntaiList ) ;
    rs.close() ;
    pstmt.close() ;
    conn.close() ;
  }
 catch( Exception ex ) {
   ex.printStackTrace() ;  }

 
return T_kinntaiList ; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值