📄 modify.jsp
字号:
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<%@page contentType="text/html;charset=GB2312"%>
<%@include file="convert.jsp"%>
<%@include file="check.jsp"%>
<jsp:useBean id="MyBean" scope="session" class="myjsp.MyBean"/>
<jsp:setProperty name="MyBean" property="*"/>
<%!
int isempty(String str) //判断递交的字符串是否为空
{
if(str.length() ==0)
return (0);
else return (1);
}
%>
<%!
String transfer(int i) //将时间数值转换为标准格式
{
if(i>=10)
return (String.valueOf(i));
else return ("0"+String.valueOf(i));
}
%>
<% Connection con = MyBean.getConnection();
Statement smt = con.createStatement();
ResultSet rs= null;
String sql;
int questionid = Integer.parseInt((String)session.getValue("questionid"));
String question = request.getParameter("question");
String item[] = {request.getParameter("item1"),request.getParameter("item2"),
request.getParameter("item3"),request.getParameter("item4"),
request.getParameter("item5"),request.getParameter("item6"),
request.getParameter("item7"),request.getParameter("item8"),
request.getParameter("item9"),request.getParameter("item10"),};
int year,month,day,hour,minute,second;
String time;
GregorianCalendar calendar;
calendar = new GregorianCalendar();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH)+1;
day = calendar.get(Calendar.DAY_OF_MONTH);
hour = calendar.get(Calendar.HOUR_OF_DAY);
minute = calendar.get(Calendar.MINUTE);
second = calendar.get(Calendar.SECOND);
time = year +"-"+transfer(month)+"-" + transfer(day) +" "+transfer(hour)+":"+transfer(minute)+":"+transfer(second);
if((isempty(item[0])+isempty(item[1])+isempty(item[2])+isempty(item[3])+
isempty(item[4])+isempty(item[5])+isempty(item[6])+isempty(item[7])+
isempty(item[8])+isempty(item[9]))==0)
{
String errmsg = "选项不得全部为空!!!";
out.print("<center><font color=green size=5>错误信息<hr></font><font color=red>"+errmsg+"</font><hr>");
out.print("<input type=button value=回上一页 onclick=history.back()>");
}
else if((isempty(item[0])+isempty(item[1])+isempty(item[2])+isempty(item[3])+
isempty(item[4])+isempty(item[5])+isempty(item[6])+isempty(item[7])+
isempty(item[8])+isempty(item[9]))<2)
{
String errmsg = "选项至少为两个!!!";
out.print("<center><font color=green size=5>错误信息<hr></font><font color=red>"+errmsg+"</font><hr>");
out.print("<input type=button value=回上一页 onclick=history.back()>");
}
else if(question.length()==0)
{
String errmsg = "问题不可为空!!!";
out.print("<center><font color=green size=5>错误信息<hr></font><font color=red>"+errmsg+"</font><hr>");
out.print("<input type=button value=回上一页 onclick=history.back()>");
}
else
{
//更新主题
sql = "update Questions set Question = '"+question+"',Date = '"+time+"',IsVisable = 0 where QuestionID = "+questionid;
smt.executeUpdate(sql);
//out.print(sql+"更新主题<p>");
//提取原有选项的记数
sql = "select ItemCount from Items where QuestionID = "+questionid;
rs = smt.executeQuery(sql);
//out.print(sql+"提取原有选项的记数<p>");
int count[]=new int[10];
int j = 0;
while(rs.next())
{
count[j]=rs.getInt(1);
j++;
}
out.print("j="+j+"<br>");
//删除选项
sql = "delete from Items where QuestionID = "+questionid;
smt.executeUpdate(sql);
//out.print(sql+"删除选项"+"<br>");
Statement _smt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
for(int i = 0,k = 0;i<=9;i++)
if(isempty(item[i])==1)
{
sql = "insert into Items(Item,QuestionID,ItemCount) values('"+item[i]+"','"+questionid+"',"+count[k]+")";//重新生成选项,并把记数恢复
_smt.executeUpdate(sql);
k++;
}
response.sendRedirect("mainform.jsp");
rs.close();
smt.close();
MyBean.close(); //关闭Connection对象
}
%>
<html>
<title>错误信息</title>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -