作为毕设作品选课系统用:关键代码如下
前端
<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]);
}