超奇怪,if和else里的代码都被执行了
student.jsp是输入要插入的记录的页面,输入信息完毕后,在该页面上点击新增按钮,提交到smid.jsp中进行插入记录到数据库的处理,使用javabean执行sql语句,在smid.jsp中定义String insert来标记是否插入成功。插入完毕后,重定向回student.jsp,并且将insert的值也传到student.jsp
以下是smid.jsp,上半部分是插入按钮的处理
<jsp:useBean id= "sdb " class= "jbean.Sdb1 " scope= "request "/>
<jsp:setProperty name= "sdb " property= "* "/>
<body>
<%
String insert= "true ";
String sno=sdb.toChinese(request.getParameter( "sno "));
String sname=sdb.toChinese(request.getParameter( "sname "));
String dept=sdb.toChinese(request.getParameter( "dept "));
String starttime=sdb.toChinese(request.getParameter( "starttime "));
String sql= " ";
ResultSet check=null;
if(request.getParameter( "tvalue ")!=null)
{
if(request.getParameter( "tvalue ").equals( "x "))//插入记录
{ if(sno!=null)
{ if(!sno.equals( " "))
{ //查询数据库中是否已经存在该学号的记录信息
String str= "select * from Students where Sno= ' "+sno+ " ' ";
check=sdb.executeQuery(str);
if(check.next())
{ insert= "yicunzai "; }
else
{ //数据库中还没有该学号的记录,可以插入
sql= "insert into Students(Sno,Sname,DeptNo,StartDate,CreditHours) values( ' "+sno+ " ', ' "+sname+ " ', ' "+dept+ " ', ' "+starttime+ " ',0) ";
insert=String.valueOf(sdb.executeUpdate(sql));
}
}
else
{
insert= "youkongzhi ";
}
}
response.sendRedirect( "student.jsp?xvalue= "+insert);
}
else
{ if(request.getParameter( "tvalue ").equals( "y "))//删除记录
{
String cbox=request.getParameter( "cbox ");
if(cbox!=null)//复选框选中了
{
String va[]=request.getParameterValues( "cbox ");
int len=java.lang.reflect.Array.getLength(va);
if(len> =1)
{
String sql2= " ";
for(int i=0;i <len;i++)
{//先删除成绩表中的相应记录
sql2= "delete from Reports where Sno= ' "+va[i]+ " ' ";
int bupdate2=sdb.executeUpdate(sql2);
sql= "delete &nbs