questionmanager.jsp
资源名称:examasp.rar [点击查看]
上传用户:hjt198082
上传日期:2015-04-16
资源大小:95k
文件大小:5k
源码类别:
MySQL数据库
开发平台:
Java
- <%@ page contentType="text/html;charset=GBK" %>
- <%@ page language="java" import="java.sql.*"%>
- <%@ page import="java.util.*" %>
- <jsp:useBean id="conn" scope="page" class="test.ConnOracle"/>
- <%@ include file="/public/checkvalidadmin.jsp"%>
- <%@ include file="/public/checkvalidadmin8.jsp"%>
- <%!
- ResultSet rs = null;
- ResultSet rsTmp = null;
- String sql = "";
- int PageSize = 13;
- int Page = 1;
- int totalPage = 1;
- String str = "";
- Hashtable ht = new Hashtable(); // Hashtable用于存储班级代号和班级信息之间的对应关系
- public String ShowOnePage(ResultSet rs, int Page, int PageSize) {
- str = "";
- // 先将记录指针定位到相应的位置
- try {
- rs.absolute( (Page-1) * PageSize + 1);
- }catch(SQLException e) {
- }
- for(int iPage=1; iPage<=PageSize; iPage++) {
- str += showOneRecord(rs,Page);
- try {
- if(!rs.next()) break;
- }catch(Exception e) {}
- }
- return str;
- }
- // 显示单行记录子模块, 由于要将当前页码传递到后面的修改和删除页面,
- // 因此,下面的shosOneRecord方法多了第二个参数
- public String showOneRecord( ResultSet rs, int page ) {
- String tt = "";
- int endindex = 16; // 在默认情况下显示题目标题中的前12个汉字字符
- String tmp = "";
- int tmpselectid = 0;
- int tmpquestionid = 0;
- try {
- tt += "<TR class=dbt4 align=middle>";
- tmpquestionid = rs.getInt("questionid");
- tt += "<TD>" + tmpquestionid + "</TD>";
- tmpselectid = rs.getInt("selectid");
- if(tmpselectid==1)
- tt += "<TD>单选</TD>";
- else if(tmpselectid==2)
- tt += "<TD><font color=blue>多选</font></TD>";
- tt += "<TD>" + (String)(ht.get(rs.getString("classid"))) + "</TD>";
- tmp = rs.getString("qname");
- if(tmp.length() < endindex)
- endindex = tmp.length();
- tt += "<TD align=left>" + tmp.substring(0,endindex) + "</TD>";
- tt += "<TD><a href=javascript:openwin(" + tmpquestionid + ")>";
- tt += "察看</a></TD>";
- tt += "<TD><a href=questionchange.jsp?id=" + tmpquestionid + "&Page=" + page + ">修改</TD>";
- tt += "<TD><a href=questiondel.jsp?id=" + tmpquestionid + "&Page=" + page + ">删除</TD>";
- tt += "</TR>";
- }catch(SQLException e) {}
- return tt;
- }
- %>
- <%
- sql = "select * from test_classinfo";
- try {
- rs = conn.executeQuery( sql );
- }catch(Exception e) {
- out.println("访问课程信息数据出错!");
- return;
- }
- if(!rs.next()) {
- out.println("系统数据库中无课程信息数据!");
- return;
- }
- do {
- ht.put(rs.getString("classid"),rs.getString("classname"));
- }while(rs.next());
- sql = "select * from test_question_lib order by questionid";
- try {
- rs = conn.executeQuery( sql );
- }catch(Exception e) {
- out.println("访问题库信息出错!");
- return;
- }
- %>
- <html>
- <head>
- <title>试题库信息维护</title>
- <link rel="stylesheet" href="../public/style.css">
- <Script language="JavaScript">
- //打开新窗口函数openwin
- function openwin(id)
- {
- window.open('questiondetails.jsp?id='+id,'infoWin', 'height=400,width=600,scrollbars=yes,resizable=yes');
- }
- </Script>
- </head>
- <body class="ss">
- <h2 ALIGN="CENTER">试题库信息维护</h2>
- <hr>
- <center>
- <table class=dbt2 width=640 cellSpacing=1 cellPadding=3 border=0>
- <tr class=dbt3 align=middle>
- <TH>题目编号</TH>
- <TH>题型</TH>
- <TH>课程名称</TH>
- <TH width=200>题目简介</TH>
- <TH>题目详细信息</TH>
- <TH colspan=2>编辑操作</TH>
- </TR>
- <%
- rsTmp = conn.executeQuery("select count(*) as mycount from test_question_lib");
- rsTmp.next();
- int totalrecord = rsTmp.getInt("mycount");
- if(totalrecord % PageSize ==0) totalPage = totalrecord / PageSize; // 如果是当前页码的整数倍
- else totalPage = (int) Math.floor( totalrecord / PageSize ) + 1; // 如果最后还空余一页
- if(totalPage == 0) totalPage = 1;
- rsTmp.close();
- try {
- if(request.getParameter("Page")==null || request.getParameter("Page").equals(""))
- Page = 1;
- else
- Page = Integer.parseInt(request.getParameter("Page"));
- // 捕获用户从浏览器地址拦直接输入类似于Page=sdfsdfsdf等非法信息所造成的异常
- } catch(java.lang.NumberFormatException e) {
- Page = 1;
- }
- if(Page < 1) Page = 1;
- if(Page > totalPage) Page = totalPage;
- out.println(ShowOnePage(rs, Page, PageSize));
- %>
- <TR class=dbt4 align=center>
- <TD colspan=7><a href=questionadd.jsp>增加新题</a></TD>
- </TR>
- </table>
- <form Action="questionmanager.jsp" Method="GET">
- <%
- if(Page != 1) {
- out.println("<A HREF=questionmanager.jsp?Page=1>第一页</A>