三、课程设计总结或结论
(正文为宋体,五号字行间距为21,提交报告时请删除本行)
1.数据库设计
数据表名:test2 注释: 无
| 字段 | 数据类型 | 注释 | 类型 |
|---|---|---|---|
| uuid | int(11) | 主键 | |
| uname | varchar(255) | ||
| upwd | varchar(255) | ||
| uinfo | varchar(255) |
数据表名:wj_admins 注释: 无
| 字段 | 数据类型 | 注释 | 类型 |
|---|---|---|---|
| username | varchar(20) | ||
| password | varchar(20) |
数据表名:wj_object 注释: 无
| 字段 | 数据类型 | 注释 | 类型 |
|---|---|---|---|
| oid | int(11) | 主键 | |
| title | varchar(1000) | ||
| discribe | varchar(1000) | ||
| createtime | date | ||
| state | int(11) | ||
| remark | varchar(20) |
数据表名:wj_question 注释: 无
| 字段 | 数据类型 | 注释 | 类型 |
|---|---|---|---|
| oid | int(11) | ||
| content | varchar(1000) | ||
| qtype | int(11) | ||
| seq | int(11) | ||
| remark | varchar(20) |
数据表名:wj_request 注释: 无
| 字段 | 数据类型 | 注释 | 类型 |
|---|---|---|---|
| oid | int(11) | ||
| a1 | varchar(1000) | ||
| a2 | varchar(1000) | ||
| a3 | varchar(1000) | ||
| a4 | varchar(1000) | ||
| a5 | varchar(1000) | ||
| a6 | varchar(1000) | ||
| a7 | varchar(1000) | ||
| a8 | varchar(1000) | ||
| a9 | varchar(1000) | ||
| a10 | varchar(1000) | ||
| a11 | varchar(1000) | ||
| a12 | varchar(1000) | ||
| a13 | varchar(1000) | ||
| a14 | varchar(1000) | ||
| a15 | varchar(1000) | ||
| a16 | varchar(1000) | ||
| a17 | varchar(1000) | ||
| a18 | varchar(1000) | ||
| a19 | varchar(1000) | ||
| a20 | varchar(1000) |
数据表名:wj_selecter 注释: 无
| 字段 | 数据类型 | 注释 | 类型 |
|---|---|---|---|
| oid | int(11) | ||
| qseq | int(11) | ||
| content | varchar(1000) | ||
| selseq | int(11) | ||
| remark | varchar(20) |
2.文件上传的数据处理
(在此说明Servlet/JSP如何读取上传的文件数据,注意,此处要有文字说明和必要的核心代码,不要全部都是说明而无代码,也不要直接罗列所有的代码。提交报告时请删除本说明部分。)
public void readFile(String fileName) throws Exception{
readFile(fileName,null);
}
public void readFile(String fileName,String charsetName) throws Exception{
InputStream in=new FileInputStream(fileName);
InputStreamReader reader;
if(charsetName==null)
reader=new InputStreamReader(in);
else
reader=new InputStreamReader(in,charsetName);
BufferedReader br=new BufferedReader(reader);
String data;
while((data=br.readLine())!=null)
System.out.println(data);
br.close();
}
public void copyFile(String from,String charsetFrom,String to,String charsetTo,String wj) throws Exception{
InputStream in=new FileInputStream(from);
InputStreamReader reader;
if(charsetFrom==null)
reader=new InputStreamReader(in);
else
reader=new InputStreamReader(in,charsetFrom);
BufferedReader br=new BufferedReader(reader);
OutputStream out=new FileOutputStream(to);
OutputStreamWriter writer=new OutputStreamWriter(out,charsetTo);
BufferedWriter bw=new BufferedWriter(writer);
PrintWriter pw=new PrintWriter(bw,true);
char s[]=wj.toCharArray();
pw.write(s);
String data;
while((data=br.readLine())!=null)
pw.println(data);
br.close();
pw.close();
}
public static void main(String[] args) throws Exception {
FileUtil util=new FileUtil();
//util.readFile("D:\\test.txt");
util.copyFile("D:\\lm.sql",null,"D:\\out.txt","utf-8","<%String id=\"141\"; %>");
//util.readFile("D:\\out.txt");
//util.readFile("d:\\out.txt","gbk");
}
说明:
完成了从一个文件中读取内容,并将其复制到另一个文件的功能。readFile()函数实现了从一个文件中读取内容的功能。copyFile()函数实现了将所读取的内容复制到另一个文件的功能
具体步骤是:
1、首先通过InputStreamReader 和BufferedReader 读取源文件;
2、然后通过OutputStreamWriter和BufferedWriter 将字符流写入输出文件;3、最后使用PrintWriter方法来打印输出的字符串。main()函数通过调用readFile()和copyFile()函数来实现前面提到的功能。
<%
ObjectBeanService obs=new ObjectBeanService();
ObjectBean bean = new ObjectBean();
String getid = request.getParameter("oid");
int oid = Integer.parseInt(getid.trim());
String title = request.getParameter("title");
String discribe = request.getParameter("discribe");
title=new String(title.getBytes("iso8859-1"),"utf-8");
discribe=new String(discribe.getBytes("iso8859-1"),"utf-8");
bean.setOid(oid);
bean.setTitle(title);
bean.setDiscribe(discribe);
int i = obs.updateObjectBean(bean);
if(i > 0){
response.sendRedirect("wjList.jsp");
}else{
response.sendRedirect("wjUpdate.jsp");
}
说明:
这段代码可以用于创建一个新的问卷对象,它将在数据库中创建一条ObjectBean记录,并以ID作为标识。然后根据ID复制一份问卷模板,并把ID写入文件中。最后通过response.sendRedirect重定向到wjList.jsp页面上。
3.问卷管理的实现
(在此说明系统中实现机制,包括如何使用JavaScript技术进行客户端的数据处理、从数据库表中进行读取和显示问卷信息,以及问卷信息如何通过页面进行显示。注意此处首先要将你设计的问卷管理界面截图,然后按照截图,给出主要的代码实现。提交报告式请删除本说明部分。)
<script type="text/javascript">
function btnOK_onclick(myForm){
var i = 0;
var subCnt = document.getElementById("subCnt").value;
var subIndex = 0;
for(i=0;i < document.myForm.elements.length && subIndex < subCnt;i++){
subIndex++;
var element = document.myForm.elements[i];
var eType = element.type;
if(eType=="radio"){
var v = "";
var subs = document.getElementsByName("radio_0" + subIndex);
var j = 0;
for(j=0;j<subs.length;j++){
if(subs[j].checked==true){
v = subs[j].value;
}
i++;
}
if(subs.length > 0){
i--;
}
if(v==""){
alert("单选框为必选");
return false;
}
}else if(eType=="select-one"){
var v = element.value;
if(v =="-1"){
alert("请选择下拉菜单的值!!");
return false;
}
}else if(eType=="checkbox"){
var v = "";
var chkName = document.getElementsByName("check_0" + subIndex);
var c=0;
for(c=0;c<chkName.length;c++){
if(chkName[c].checked==true){
v = chkName[c].value;
}
i++;
}
if(chkName.length > 0){
i--;
}
if(v==""){
alert("复选框至少得选一个选项!!");
return false;
}
}
}
document.forms[0].action="doRequest.jsp?oid=<%=oid%>";
document.forms[0].submit();
return true;
}
function btnOK_click2(){
alert("该主题评议已终止!!");
}
function btnBack_onclick(){
document.forms[0].action="wjList.jsp";
document.forms[0].submit();
}
</script>
说明:
这个代码实现了一些表单验证功能,当用户提交表单时,会检查该表单中的单选框、下拉菜单和复选框是否已正确填写,如果未正确填写则会返回相应的警告。此外,该代码还可以根据用户的不同操作对页面进行跳转,以便实现特定功能。
// 根据问卷的编号查找该属于该问卷的题目
public List litQuesByOid(int oid) {
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
List quesList=new LinkedList();
String sql = "select seq,content,qtype from wj_question where oid='"
+ oid + "' order by seq asc";
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
rs = stm.executeQuery(sql);
while(rs.next()){
Question ques=new Question();
int seq=rs.getInt("seq");
int qtype=rs.getInt("qtype");
String content=rs.getString("content");
ques.setContent(content);
ques.setSeq(seq);
ques.setQtype(qtype);
quesList.add(ques);
}
return quesList;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
dbcon.closeAll(con, stm, rs);
}
}
public int addQues(int oid, String content, int qtype, int seq) {
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
String sql = "insert into wj_question(oid,content,qtype,seq) values('"
+ oid + "','" + content + "','" + qtype + "','"
+ seq + "')";
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
int i = stm.executeUpdate(sql);
return i;
} catch (Exception e) {
e.printStackTrace();
return 0;
} finally {
dbcon.closeAll(con,stm,rs);
}
}
// 插入题目前先修改题目表的题目顺序号
public int updateQuesOrder(int oid, int seq) {
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
String sql = "update wj_question set seq=(seq + 1) where oid = '" + oid
+ "'and seq > '" + seq + "'";
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
int i = stm.executeUpdate(sql);
return i;
} catch (Exception e) {
e.printStackTrace();
return 0;
} finally {
dbcon.closeAll(con, stm, rs);
}
}
// 编辑题目的时候 先的到它的题目TITLE ,选项类型,选项内容
public Question getQuesBySeq(int seq, int oid) {
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
Question ques=new Question();
String sql = "select content,qtype from wj_question where oid = '" + oid
+ "' and seq = '" + seq + "'";
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
rs = stm.executeQuery(sql);
while(rs.next()){
String content=rs.getString("content");
int qtype=rs.getInt("qtype");
ques.setContent(content);
ques.setQtype(qtype);
}
return ques;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
dbcon.closeAll(con,stm,rs);
}
}
// 根据传进来的问卷编号和试题的顺序号 删除题目
public int deleteQues(int seq, int oid) {
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
int count=0;
String sql = "delete from wj_question where oid=" + oid + " and seq = "+ seq ;
System.out.println(sql);
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
count = stm.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
} finally {
dbcon.closeAll(con,stm,rs);
}
return count;
}
// 根据传进来的问卷编号和题目的序号 修改题目表中题目的顺序
public int updateQseq(int seq, int oid) {
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
int count=0;
String sql = "update wj_question set seq=(seq-1) where oid = " + oid+ " and seq > " + seq ;
System.out.println(sql);
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
count = stm.executeUpdate(sql);
} catch (Exception e) {
e.printStackTrace();
return 0;
} finally {
// 关闭连接,释放资源
dbcon.closeAll(con, stm, rs);
}
return count;
}
public int getQuesCount(int oid) {// 得到问题的总数
DBConnection dbcon = null;
Connection con = null;
Statement stm = null;
ResultSet rs = null;
int qcount = 0;
try {
dbcon=new DBConnection();
con=dbcon.getConnection();
stm=con.createStatement();
String sql = "select count(*) from wj_question where oid=" + oid;
rs = stm.executeQuery(sql);
while (rs.next()) {
qcount = rs.getInt(1);
}
} catch (Exception e) {
e.printStackTrace();
}finally{
dbcon.closeAll(con, stm, rs);
}
System.out.println("问题总数qcount:" + qcount);
return qcount;
}
说明:
这里的代码实现了对问卷的两个操作,第一个操作是根据问卷的编号查找该属于该问卷的题目,使用DBConnection类进行数据库连接,从数据库中查询出题目信息,存储到Question对象中并将其放入LinkedList容器中返回。第二个操作是向数据库中插入新的题目,使用Statement.executeUpdate()方法执行SQL语句,具体可看代码注释。