动态添加,删除行之考试系统
数据库设计:
xl_option 题目选项
20090105134755404(编号) 20090105134904421(外键) 比较符合(选项内容) ②(选项标号) 2(选项分值)
xl_subject 题目信息
20090105134943608(编号)20090105114648137(外键) 我认为收入可观,福利待遇好,我很满意(题目内容) 管理员 2009-01-05
xl_subject_type 题目类型
20090105114707048(编号) 人际关系满意感维度(题目类型) 管理员 2009-01-05
subject_add.jsp
<form name="subjectForm" action="subject.do?type=add" method="POST">
<TABLE border="0" align="center" class="listtable">
<TR>
<TH>题目类型</TH>
<TD>
<%
SysEmployee sysEmployee = (SysEmployee) session.getAttribute("EMPLOYEE");
XlSubjectTypeDAO dao = new XlSubjectTypeDAO();
XlSubjectType ty = new XlSubjectType();
List list = dao.selectWhere();
%>
<select name="xlSubjectType" id="xlSubjectType">
<option value="0">
---请选择---
</option>
<%
for (int i = 0; i < list.size(); i++) {
ty = (XlSubjectType) list.get(i);
%>
<option value="<%=ty.getTypeId()%>">
<%=ty.getSubjectType()%>
</option>
<%
}
%>
</select>
</TD>
</TR>
<TR>
<TH>题目内容</TH>
<TD><textarea name="subjectText" rows="3" cols="50"></textarea></TD>
</TR>
<tr><TH>为本题配置答案</TH></tr>
<tr>
<td colspan="2">
<table width="100%" border="0" class="listtable" id="tablea">
<tr>
<TH>编号</TH>
<TH>答案标识</TH>
<TH>答案内容</TH>
<TH>分数</TH>
<TH><img src="http://www.cnblogs.com/share/css/images/crm_add.gif" alt="增加" width="14" height="14" style="CURSOR: hand"
onClick="insertRowadd()">
</TH>
</tr>
<tr>
<td>
<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="1">
<input type="hidden" value="<%=DealString.getID()%>" name="ide" id="ide">
</td>
<td>
<input name="eitem2" type="text" id="eitem2" value="①" size="15">
</td>
<td>
<textarea name="eitem3" id="eitem3" rows="" cols="30">非常不符合</textarea>
</td>
<td>
<input name="eitem4" type="text" id="eitem4" size="15" value="1">
</td>
<td> </td>
</tr>
<tr>
<td>
<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="2">
<input type="hidden" value="<%=DealString.getID()%>" name="ide" id="ide">
</td>
<td>
<input name="eitem2" type="text" id="eitem2" value="②" size="15">
</td>
<td>
<textarea name="eitem3" id="eitem3" rows="" cols="30">比较不符合</textarea>
</td>
<td>
<input name="eitem4" type="text" id="eitem4" size="15" value="2">
</td>
<td>
<img src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除"
width="16" height="16" style="cursor:hand"
onClick="this.parentNode.parentNode.removeNode(true)">
</td>
</tr>
<tr>
<td>
<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="3">
<input type="hidden" value="<%=DealString.getID()%>" name="ide" id="ide">
</td>
<td>
<input name="eitem2" type="text" id="eitem2" value="③" size="15">
</td>
<td>
<textarea name="eitem3" id="eitem3" rows="" cols="30">说不清楚</textarea>
</td>
<td>
<input name="eitem4" type="text" id="eitem4" size="15" value="3">
</td>
<td>
<img src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除" width="16" height="16" style="cursor:hand"
onClick="this.parentNode.parentNode.removeNode(true)">
</td>
</tr>
<tr>
<td>
<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="4">
<input type="hidden" value="<%=DealString.getID()%>" name="ide" id="ide">
</td>
<td>
<input name="eitem2" type="text" id="eitem2" value="④" size="15">
</td>
<td>
<textarea name="eitem3" id="eitem3" rows="" cols="30">比较符合</textarea>
</td>
<td>
<input name="eitem4" type="text" id="eitem4" size="15" value="4">
</td>
<td>
<img src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除"
width="16" height="16" style="cursor:hand"
onClick="this.parentNode.parentNode.removeNode(true)">
</td>
</tr>
<tr>
<td>
<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="5">
<input type="hidden" value="<%=DealString.getID()%>" name="ide" id="ide">
</td>
<td>
<input name="eitem2" type="text" id="eitem2" value="⑤" size="15">
</td>
<td>
<textarea name="eitem3" id="eitem3" rows="" cols="30">非常符合</textarea>
</td>
<td>
<input name="eitem4" type="text" id="eitem4" size="15" value="5">
</td>
<td>
<img src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除"
width="16" height="16" style="cursor:hand"
onClick="this.parentNode.parentNode.removeNode(true)">
</td>
</tr>
</table>
</td>
</tr>
<TR>
<TH>发布人</TH>
<TD>
<input type="text" name="subjectItem1" id="subjectItem1" style="width:80" maxlength="30" class="input"
value="<%=DealString.toString(sysEmployee.getEmployeeName())%>">
</TD>
</TR>
<TR>
<TH>发布日期</TH>
<TD>
<INPUT type="text" name="subjectItem2" id="subjectItem2" style="width:80" maxlength="30"
value="<%=DealString.getDateTime().substring(0, 10)%>" class="input" onFocus="setday(this)">
(格式:YYYY-MM-DD)
</TD>
</TR>
</table>
<table width="100%" border="0">
<TR>
<TD colspan="2" align="center">
<div align="center">
<INPUT type="submit" name="B1" value="确 定" class="button" onClick="return add()">
<input type="button" name="B1" value="返 回" class="button" onClick="javascript:history.back()">
</div>
</TD>
</TR>
</table>
</form>
</body>
</html>
<script language="javascript">
function insertRowadd(){
objTR1 = tablea.insertRow();
var obj=document.getElementById("tablea");
var rowIndex=obj.childNodes[0].childNodes.length-1;
var dt = new Date();
var ms = dt.getTime();
var objTD10 = objTR1.insertCell();
var objTD11 = objTR1.insertCell();
var objTD12 = objTR1.insertCell();
var objTD13 = objTR1.insertCell();
var objTD19 = objTR1.insertCell();
objTD10.className = 'InputAreaCell';
objTD11.className = 'InputAreaCell';
objTD12.className = 'InputAreaCell';
objTD13.className = 'InputAreaCell';
objTD19.className = 'InputAreaCell';
objTD10.innerHTML ='<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="'+rowIndex+'" >'+
'<input type="hidden" value="'+ms+'" name="ide" id="ide">';
objTD11.innerHTML ='<input name="eitem2" type="text" id="eitem2" size="15">';
objTD12.innerHTML ='<textarea name="eitem3" id="eitem3" rows="" cols="30"></textarea>';
objTD13.innerHTML ='<input name="eitem4" type="text" id="eitem4" size="15">';
if(rowIndex != "1"){
objTD19.innerHTML='<img src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除" width="16" height="16" style="cursor:hand" onClick="this.parentNode.parentNode.removeNode(true)">';
}else{
objTD19.innerHTML=' ';
}
}
function add()
{
var xlSubjectType=document.getElementById("xlSubjectType").value;
if(xlSubjectType=="0")
{
alert("请选择题目类型");
return false;
}
var ide=document.getElementById("ide").value;
if(ide=="")
{
//alert("1231231");
return false;
}
}
</script>
subject_edit.jsp
<body>
<%
//SysEmployee employee = (SysEmployee) session.getAttribute("EMPLOYEE");
String id = DealString.toString(request.getParameter("id"));
XlSubjectDAO xltdao=new XlSubjectDAO();
XlSubject xlt=new XlSubject();
if(!"".equals(id)){
xlt=xltdao.findById(id);
}
%>
<form name="subjectForm" action="subject.do?type=edit&id=<%=id%>"
method="POST">
<TABLE align="center" class="listtable">
<TR>
<TH>题目类型</TH>
<TD>
<select name="xlSubjectType" >
<option value="-1">全部题目类型</option>
<%
XlSubjectTypeDAO xlsdao = new XlSubjectTypeDAO();
XlSubjectType xst=new XlSubjectType();
List listxlstype=xlsdao.selectAll();
for(int xlstypeindex=0;xlstypeindex<listxlstype.size();xlstypeindex++){
xst=(XlSubjectType)listxlstype.get(xlstypeindex);
%>
<option value="<%=xst.getTypeId()%>" <%if(xst.getTypeId().equals(xlt.getXlSubjectType().getTypeId()))out.print("selected");%>><%=xst.getSubjectType() %></option>
<%
}
%>
</select>
</TD>
</TR>
<TR>
<TH>题目内容</TH>
<TD><textarea name="subjectText" rows="3" cols="50"><%=DealString.toString(xlt.getSubjectText())%></textarea>
</TD>
</TR>
<tr>
<td colspan="2">
<table width="100%" class="listtable" id="tablea">
<tr>
<th>编号</th>
<th>答案标识</th>
<th>答案内容</th>
<th>分数</th>
<th>
<img src="http://www.cnblogs.com/share/css/images/crm_add.gif" alt="增加" width="14" height="14" style="CURSOR: hand"
onClick="insertRowadd()">
</th>
</tr>
<%
XlOptionDAO dao2 = new XlOptionDAO();
XlOption op = new XlOption();
List list3 = dao2.select(id);
int count = 0;
for (int k = 0; k < list3.size(); k++) {
op = (XlOption) list3.get(k);
count++;
%>
<tr>
<td>
<input name="idcount" type="text" value="<%=count%>" size="15" />
<input name="ide" type="hidden" size="15" id="ide" value="<%=DealString.toString(op.getOpId())%>">
</td>
<td>
<input name="eitem2" type="text" size="15" id="eitem2" value="<%=DealString.toString(op.getOptionNumber())%>">
</td>
<td>
<textarea name="eitem3" id="eitem3" cols="30"><%=DealString.toString(op.getOptionText())%></textarea>
</td>
<td>
<input name="eitem4" type="text" size="15" id="eitem4" value="<%=DealString.toString(op.getOpItem1())%>">
</td>
<td>
<img border="0" src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除" width="16" height="16" style="cursor:hand" onClick="this.parentNode.parentNode.removeNode(true)">
</td>
</tr>
<%
}
%>
</table>
</td>
</tr>
<TR>
<TH>发布人</TH>
<TD>
<input type="text" name="subjectItem1" id="subjectItem1" style="width:80" maxlength="30" class="input"
value="<%=DealString.toString(xlt.getSubjectItem1())%>">
</TD>
</TR>
<TR>
<TH>
发布日期
</TH>
<TD>
<INPUT type="text" name="subjectItem2" id="subjectItem2" style="width:80" maxlength="30" class="input"
onFocus="setday(this)" value="<%=DealString.toString(xlt.getSubjectItem2())%>">
(格式:YYYY-MM-DD)
</TD>
</TR>
</table>
<table width="100%" border="0" align="center" class="listtable">
<TR>
<TD colspan="2" align="center">
<div align="center">
<INPUT type="submit" name="B1" value="确 定" class="button">
<input type="button" name="B1" value="返 回" class="button" onClick="javascript:history.back()">
</div>
</TD>
</TR>
</table>
</form>
<script language="javascript">
function checkNews()
{
var check2 =document.getElementById("subjectType").value;
if(check2=='')
{
alert("请输入类型标题!");
document.getElementById("subjectType").focus();
return false;
}
}
</script>
</body>
</html>
<script language="javascript">
function insertRowadd(){
objTR1 = tablea.insertRow();
var obj=document.getElementById("tablea");
var rowIndex=obj.childNodes[0].childNodes.length-1;
var dt = new Date();
var ms = dt.getTime();
var objTD10 = objTR1.insertCell();
var objTD11 = objTR1.insertCell();
var objTD12 = objTR1.insertCell();
var objTD13 = objTR1.insertCell();
var objTD19 = objTR1.insertCell();
objTD10.className = 'InputAreaCell';
objTD11.className = 'InputAreaCell';
objTD12.className = 'InputAreaCell';
objTD13.className = 'InputAreaCell';
objTD19.className = 'InputAreaCell';
objTD10.innerHTML ='<input align="center" name="eitem1" type="text" id="eitem1" size="15" value="'+rowIndex+'" >'+
'<input type="hidden" value="'+ms+'" name="ide" id="ide">';
objTD11.innerHTML ='<input name="eitem2" type="text" id="eitem2" size="15">';
objTD12.innerHTML ='<textarea name="eitem3" id="eitem3" rows="" cols="30"></textarea>';
objTD13.innerHTML ='<input name="eitem4" type="text" id="eitem4" size="15">';
if(rowIndex != "1"){
objTD19.innerHTML='<img src="http://www.cnblogs.com/share/css/images/delete.gif" alt="删除" width="16" height="16" style="cursor:hand" onClick="this.parentNode.parentNode.removeNode(true)">';
}else{
objTD19.innerHTML=' ';
}
}
</script>
3,StrutsAction.java
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
SubjectForm subjectForm = (SubjectForm) form;// TODO Auto-generated
// method stub
XlSubject x = new XlSubject();
XlOptionDAO daoOp = new XlOptionDAO();
XlSubjectType xl = new XlSubjectType();
XlSubjectDAO dao = new XlSubjectDAO();
String subId = String.valueOf(DealString.getID());
String type = request.getParameter("type");
String id = request.getParameter("id");
String subjectText = subjectForm.getSubjectText();
String subjectItem1 = subjectForm.getSubjectItem1();
String subjectItem2 = subjectForm.getSubjectItem2();
String xlSubjectType = request.getParameter("xlSubjectType");
String eitem1[] = subjectForm.getEitem1();
String eitem2[] = subjectForm.getEitem2();
String eitem3[] = subjectForm.getEitem3();
String eitem4[] = subjectForm.getEitem4();
String ide[] = subjectForm.getIde();
if("del".equals(type)){
dao.delete(id);
}else{
if ("edit".equals(type))
{
//清空值
dao.delete(id);
}
x.setSubId(subId);
xl.setTypeId(xlSubjectType);
x.setSubjectItem1(subjectItem1);
x.setSubjectItem2(subjectItem2);
x.setSubjectText(subjectText);
x.setXlSubjectType(xl);
dao.save(x);
if (ide != null) {
if (ide.length > 0) {
for (int i = 0; i < ide.length; i++) {
XlOption op = new XlOption();
op.setOpId(subjectForm.getIde()[i]);
op.setXlSubject(x);
op.setOptionText(subjectForm.getEitem3()[i]);
op.setOpItem1(subjectForm.getEitem4()[i]);
op.setOptionNumber(subjectForm.getEitem2()[i]);
daoOp.save(op);
}
}
}
}
request.setAttribute("url", "/manage/xlcs/subject_List.jsp");
return mapping.findForward("success");
}