📄 updatetest.jsp
字号:
int mark=0;
for( i=1;i<strArray.length;i++){//提交每一道试题
if(debug){
out.println("<br>test("+i+"):<br>"+strArray[i]);
}
bin=strArray[i].indexOf("@");
end=strArray[i].lastIndexOf("@");
temp=strArray[i].substring(bin+1,end+1);//答案
ansMark=temp.split("@");
int tippos=strArray[i].indexOf("#tip");
String t1=strArray[i].substring(0,bin)+strArray[i].substring(tippos).trim();
//将答案串从试题文本中删除,因为单个试题文本中没有这些信息
//提交单个试题
mark+=Float.parseFloat(ansMark[1]);
try{
newID=submitOne(t1,ansMark[0],Float.parseFloat(ansMark[1]),ansMark[2],con,true);
if(debug && newID!=-1){
out.println("<br>database submit success:newID="+newID);
}
if(newID!=-1){
//试题ID@答案@分数@难易度; 一道试题的格式,以#号结束
temp=String.valueOf(newID)+"@"+ansMark[0].trim() +"@"+ansMark[1].trim() +"@"+ansMark[2].trim() +"#";
bs.append(temp);
}else
{
throw new Exception("试题格式可能出错");
}
}catch(IllegalArgumentException ie)
{
msgsb.append("试题格式可能出错 test("+i+")=:"+t1+temp+"<br>"+ie);
out.print("<br>"+msgsb.toString());
}
}
//提交试卷
if(msgsb.toString().equals("OK")){
try{
// sql="insert into test(id,date,testtypeid,paper,title,subid,gradeid,status,teaid,validtime,testnum) values(38,'2003-09-18 14:10:44',1,'117@A@5@A#118@B@6@B#119@C@7@C#120@D@8@E#','',1,1,2,1,3,4)";
// con.setAutoCommit(false);
// stmt=con.createStatement();
// stmt.executeUpdate(sql);
// stmt.close();
sql="insert into test(date,testtypeid,paper,title,subid,gradenote,status,teaid,validtime,testnum,"+
"knowpointid1,knowpointid2,knowpointid3,mark) "+
"values('"+now+"',"+"1"+",'"+bs.toString() +"','"+Title+"',"+subjectID+","+"'"+gradeID+"'"+
","+"2"+","+teaID+","+"3"+","+(strArray.length-1) +","+
knowPointID1+","+knowPointID2+","+knowPointID3+","+mark+")";
//缺省testtypeid=1:单一的选择题;statue=2:已经发布;validtiem=3:有效期为3年
Statement stmt=con.createStatement();
stmt.executeUpdate(sql);
stmt.close();
if(debug){
Tools.debugmsg("<br>insert into test:SQL="+sql,out);
}
stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select LAST_INSERT_ID() as newid from question");
if(rs.next()){
newtestID=rs.getInt("newID");
rs.close();
stmt.close();
}
con.commit();
if(debug){
out.print("<br> new test ID is:"+newtestID);
stmt=con.createStatement();
rs=stmt.executeQuery("select id,paper,title from test where id="+newtestID);
if (rs.next()){
Tools.debugmsg("<br> the newest paper is:"+rs.getString("paper"),out);
Tools.debugmsg("<br> the title of the paper is:"+rs.getString("title"),out);
}
rs.close();
stmt.close();
}
}
catch(SQLException e){
try{
con.rollback();
}catch(Exception e1){
msgsb.append("<BR>rollbackcbd:SQL="+sql+"\n"+e1.toString());
}
msgsb.append("insert Error:SQL="+sql+"\n"+e.toString());
}
}else{
try{
con.rollback();
}catch(Exception e2){
msgsb.append("rollback:SQL="+sql+"\n"+e2.toString());
}
msgsb.append("Single test is error i="+i);
}
}catch(Exception e){
try{
con.rollback();
}catch(Exception e1){
msgsb.append("<BR>rollbackcbd:SQL="+sql+"\n"+e1.toString());
}
msgsb.append("<br>Batch submit Error\n"+
"<br>strArray["+i+"]="+strArray[i]+"<br>"+e.toString() );
Tools.debugmsg("<br>i="+i,out);
}
return newtestID;
}
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>试题提交</title>
</head>
<body>`
<%
try{
//UN_debug
msgsb.delete(0,msgsb.length() );
msgsb.append("OK");
try{
String TeacherID=(String)session.getAttribute("teacherID");
//Tools.showalert("teaID="+TeacherID,out);
//Tools.showalert("msgdb="+msgsb.toString(),out);
//Tools.showalert(TeacherID,out);
teaID=Integer.parseInt(TeacherID);
}catch(Exception e){
Tools.showalert("您还没有登录,或连接超时,请重新登录!",out);
//response.sendRedirect("../login.jsp");
msgsb.append("teacherID Error\n");
Tools.showJS("window.open('../login.jsp','_self')",out);
//response.sendRedirect("../login.jsp");
// Tools.goback(out);
}
if (msgsb.toString().equals("OK"))
{
questTypeID=""+request.getParameter("QuestType");//试题类型ID
subjectID=Integer.parseInt(request.getParameter("Subject"));//科目ID
gradeID=""+request.getParameter("Grade");//年级ID
//difficulty=""+request.getParameter("Difficulty");//难度
knowPointID1=""+request.getParameter("KnowPoint1");//知识点ID
knowPointID2=""+request.getParameter("KnowPoint2");//知识点ID
knowPointID3=""+request.getParameter("KnowPoint3");//知识点ID
//answer=""+request.getParameter("Answer");//答案
//answer=Tools.codestring(answer);
float mark=0;//Float.parseFloat(request.getParameter("Mark"));//分数
String strHtml=""+request.getParameter("Content");//获取提交的试题的HTML
//debug
con=DBCon.getConnection();
//
strHtml=Tools.codestring(strHtml);//转换字符集
String group=""+request.getParameter("group");
if(group.equals("single")){//提交单个试题
ID=submitOne(strHtml,answer,mark,difficulty,con,false);
}else{
if(group.equals("suit") ){
String Title=""+request.getParameter("suit_title");
Title=Tools.codestring(Title);
ID=submitAll(strHtml,Title,con,out);
}
}
%>
<%temp=msgsb.toString();
if(debug){
out.print("<br><br><br>New Information");
out.print(temp);
}
if(temp.equals("OK")){
//提交成功
if(group.equals("single")){//提交单个试题
Tools.showalert(" 试题提交成功,新的试题ID为:"+ID,out);
Tools.goback(out);
}else if(group.equals("suit")){
Tools.showalert(" 试卷提交成功,新的试卷ID为:"+ID,out);
Tools.goback(out);
}
%>
<%
}
else{
System.out.print(msgsb.toString());
%>
<SCRIPT language="javascript">
alert("试题未能提交成功,请检查提交信息或与系统管理员联系");
//history.go(-1);
</SCRIPT>
<%
}
%>
</body>
</html>
<%
}
%>
<%}
catch(Exception e){
System.out.print(e.toString());
}
finally{
DBCon.dropConnection();
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -