struts2通过checkbox 选择多条记录,并在后台提取

作为毕设作品选课系统用:关键代码如下

前端

<script type="text/javascript">
function SelectChecked(){
	var objselectValue = "";
    var bookselectValue = "";
    var objflag = false;
    var objselect = document.getElementsByName("objselect");
    var bookselect = document.getElementsByName("bookseleck");
    for(i=0;i<objselect.length;i++)
        {
        
        if(objselect[i].checked){
                objselectValue+=","+objselect[i].value;
                objflag = true;
        }
    }
    for(i=0;i<bookselect.length;i++)
        {
        
        if(bookselect[i].checked){
                bookselectValue+=","+bookselect[i].value;
        }
    }
    if(objflag==false)
        {
        alert("至少你要选择一门课程");
        return false;
        }
}
html:
<body>
	<form method="post" action="selected" id="selected" οnsubmit="SelectChecked()">
<div class="div_4">
			<fieldset>
				<legend>供选课程</legend>
				<table class="table table-bordered">
					<tr>
						<th>选课</th>
						<th>预定教材</th>
						<th>课程名称</th>
						<th>课程代码</th>
						<th>教师姓名</th>
						<th>上课时间</th>
						<th>上课地点</th>
						<th>学分</th>
						<th>周学时</th>
						<th>起始结束周</th>
						<th>容量</th>
						<th>余量</th>
						<th>课程性质</th>
						<th>开课学院</th>
						<th>考试时间</th>
					</tr>
					<!--课程供选数据填充处-->
					<s:iterator value="#session.cruObjects">
						<tr>
							<td><label><input type="checkbox" name="objselect" value="<s:property value="objnum"/>"
												></label></td>
							<td><label><input type="checkbox" name="bookselect" value="<s:property value="objnum"/>"
												></label></td>
							<td><s:property value="objname"/></td>
							<td><s:property value="objnum"/></td>
							<td><s:property value="teaname"/></td>
							<td><s:property value="objtime"/></td>
							<td><s:property value="place"/></td>
							<td><s:property value="credits"/></td>
							<td><s:property value="ltimes"/></td>
							<td><s:property value="objtime"/></td>
							<td><s:property value="allowance"/></td>
							<td><s:property value="capacity"/></td>
							<td><s:property value="judgeobjecttakecpl"/></td>
							<td><s:property value="clgname"/></td>
							<td><s:property value="examtime"/></td>
						</tr>
					</s:iterator></table>
			</fieldset>
		</div>
		<div>
	            <input type="submit" value=" 提交  " class="btn">
		</div>

struts配置文件:

<!-- 学生选课课程提交 -->
    	<action name="selected" class="cn.helrioner.action.Obj_StuAction" method="selectobj">
    		<result name="success">/jsp/view/homePageview.jsp</result>
    	</action>
action提取选课信息关键代码:
private long[]objselect=new long[]{};
	private long[]bookselect=new long[]{};
	

	public long[] getBookselect() {
		return bookselect;
	}

	public void setBookselect(long[] bookselect) {
		this.bookselect = bookselect;
	}

	public long[] getObjselect() {
		return objselect;
	}
      public void setObjselect(long[] objselect) {
		this.objselect = objselect;
	}
         public String selectobj(){
System.out.println("所选课程:");
    for(int i=0;i<this.objselect.length;i++){
        System.out.println((int)objselect[i]);
       }
    System.out.println("所选教科书:");
    for(int i=0;i<this.bookselect.length;i++){
        System.out.println((int)bookselect[i]);
       }
           


           




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值