📄 checkpaper.jsp
字号:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ page import="com.study.database.*"%>
<%@ page import="java.sql.*"%>
<%@ page import="javax.sql.*"%>
<%@ page import="com.study.vo.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'checkpaper.jsp' starting page</title>
</head>
<body>
<%
String choice="";
String opinion="";
String discuss="";
String subject="";
String answer="";
int total = 0;
int correct = 0;
String papertitle = new String(request.getParameter("papertitle").getBytes("ISO-8859-1"),"GB18030");
DBConnectionManage db = new DBConnectionManage();
int count= 1;
Connection conn = db.getFreeConnection();
String query = "select * from paper p,exam e where e.paperid = p.paperid and p.papertitle = ?";
PreparedStatement psmt = null;
ResultSet rs = null;
try{
psmt = conn.prepareStatement(query);
psmt.setString(1,papertitle);
rs = psmt.executeQuery();
while(rs.next()){
choice = rs.getString("choiceid");
opinion = rs.getString("opinionid");
discuss = rs.getString("discussid");
}
}catch(Exception ex){
out.println("数据库出错"+ex.getMessage());
}finally{
psmt.close();
rs.close();
db.closeConnection(conn);
}
query = "select * from subject where subjectid in ("+choice+")";
conn = db.getFreeConnection();
try{
psmt = conn.prepareStatement(query);
rs = psmt.executeQuery();
while(rs.next()){
answer = request.getParameter("subject_"+rs.getString("subjectid"));
if(answer!=null&&answer.equalsIgnoreCase(rs.getString("subjectanswer"))){
correct++;
}
total++;
}
}catch(Exception ex){
out.println("查找试题"+ex.getMessage());
}finally{
psmt.close();
rs.close();
db.closeConnection(conn);
}
out.println("选择题一共"+total+"题"+"您答对了<font color='#FF0000'>"+correct+"</font>题<br>");
total = 0;
correct = 0;
query = "select * from subject where subjectid in ("+opinion+")";
conn = db.getFreeConnection();
try{
psmt = conn.prepareStatement(query);
rs = psmt.executeQuery();
while(rs.next()){
answer = request.getParameter("subject_"+rs.getString("subjectid"));
if(answer!=null&&answer.equalsIgnoreCase(rs.getString("subjectanswer"))){
correct++;
}
total++;
}
}catch(Exception ex){
out.println("查找试题出错"+ex.getMessage());
}finally{
psmt.close();
rs.close();
db.closeConnection(conn);
}
out.println("判断题一共"+total+"题"+"您答对了<font color='#FF0000'>"+correct+"</font>题<br>");
total = 0;
correct = 0;
query = "select * from subject where subjectid in ("+discuss+")";
conn = db.getFreeConnection();
try{
psmt = conn.prepareStatement(query);
rs = psmt.executeQuery();
while(rs.next()){
answer = request.getParameter("subject_"+rs.getString("subjectid"));
if(answer!=null&&answer.equalsIgnoreCase(rs.getString("subjectanswer"))){
correct++;
}
total++;
}
}catch(Exception ex){
out.println("查找试题"+ex.getMessage());
}finally{
psmt.close();
rs.close();
db.closeConnection(conn);
}
out.println("论述题一共"+total+"题"+"您答对了<font color='#FF0000'>"+correct+"</font>题<br>");
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -