问题描述
我要做的事情是大致这样的:我在做关于送养和领养动物的网站,在apply1.jsp里面我是从数据库的进度表(里面有AID,UID,adate,ddate,atype,pass)取出UID,AID,adate来告诉管理员UID(某用户)在adate(时间)申请了对AID(某动物)的送养申请,然后把这条信息弄成checkbox,当管理员选中某条信息的时候并按了通过的时候,就会将UID(这里之所以在后面再添个零是用来和领养做区别的)提交到pass.jsppass.jsp里面则提出checkbox里面的值,即jd.getAID()0;首先判断是否为空,为空就执行else部分,不为空则执行if部分,if部分里面我将一个个值提出来并与2作模运算,如果能除尽说明最后一个数字为0,即为通过送养申请,然后将它转换为int并赋值给AID,然后AID除以10就能得到在apply1.jsp中原本传进的AID值,最后将type=0来说明是送养的申请通过,接着就是在数据库里搜索相关的信息,并将这条信息的pass=1(说明通过),ddate=当前时间(通过的时间)因为是菜鸟刚接触没多久,所以页面比较混乱而且都在jsp中写的。。。可是运行的时候它是运行了else部分的,请问一下为什么是空的呢?还有应该怎么改呢?麻烦尽量在jsp中改。。。因为不是很熟悉其他的拜托了!!!!!!!!!!!!!!!!!!!!!!!!这是apply1.jsp里的代码:<%@pagelanguage="java"import="java.util.*"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%@pageimport="java.sql.*"%><%@pageimport="animals.jindu"%><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'apply.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body><fontsize=5style="color:Teal;">送养申请:</font><br><%try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();//connectionConnectionconn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=work1","cly","123456");System.out.println("Databaseconnection");Statementstmt=conn.createStatement();Stringsql="select*from进度表whereatype='0'andpass='0'";ResultSetrs=stmt.executeQuery(sql);List<jindu>list=newArrayList<jindu>();while(rs.next()){jindujd=newjindu();jd.setAID(rs.getInt("AID"));jd.setUID(rs.getString("UID"));jd.setAdate(rs.getString("adate"));list.add(jd);}request.setAttribute("list",list);rs.close();stmt.close();conn.close();}catch(Exceptione){e.printStackTrace();}List<jindu>list=(List<jindu>)request.getAttribute("list");if(list!=null&&list.size()>=1){for(jindujd:list){%><formid="form1"method="post"><tr><td><inputtype="checkbox"id="checkbox"name="chexkbox"value="<%=jd.getAID()%>0"/><ahref="msg.jsp?UID=<%=jd.getUID()%>"><%=jd.getUID()%></a> 在 <%=jd.getAdate()%> 提出了对动物编号为 <ahref="details.jsp?aid=<%=jd.getAID()%>"><%=jd.getAID()%></a> 的送养申请<td></tr><%}%><br><br><inputtype="button"value="通过"type="submit"onclick="form1.action='pass.jsp';form1.submit();"/> <inputtype="button"value="不通过"type="submit"onclick="form1.action='notPass.jsp';form1.submit();"/></form><%}if(list==null||list.size()<1){out.print("<tr><tdbgcolor='#FFFFFF'colspan='5'>没有申请送养信息!</td></tr>");}%></body></html>这是pass.jsp里的代码:<%@pagelanguage="java"import="java.util.*"contentType="text/html;charset=UTF-8"pageEncoding="UTF-8"%><%Stringpath=request.getContextPath();StringbasePath=request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><%@pageimport="java.sql.*"%><%@pageimport="java.util.Date"%><%@pageimport="java.text.SimpleDateFormat"%><%Datedate=newDate();SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-dd");Stringtoday=df.format(date);%><%String[]selected=request.getParameterValues("checkbox");%><!--取出AID的值然后IFAID/2==0AID/=10;INTTYPE=0;送养ELSEAID-=1;AID/=10;领养--><!DOCTYPEHTMLPUBLIC"-//W3C//DTDHTML4.01Transitional//EN"><html><head><basehref="<%=basePath%>"><title>MyJSP'notPass.jsp'startingpage</title><metahttp-equiv="pragma"content="no-cache"><metahttp-equiv="cache-control"content="no-cache"><metahttp-equiv="expires"content="0"><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="Thisismypage"><!--<linkrel="stylesheet"type="text/css"href="styles.css">--></head><body><%try{Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();//connectionConnectionconn=DriverManager.getConnection("jdbc:sqlserver://localhost:1433;DatabaseName=work1","cly","123456");Statementstmt=conn.createStatement();inttype;intAID;introw=0;if(selected!=null&&selected.length!=0){for(inti=0;i<selected.length;i++){AID=Integer.parseInt(selected[i]);if(AID/2==0){AID/=10;type=0;}else{AID-=1;AID/=10;type=1;}Stringsql="update进度表 set pass='1'andddate='"+today+"'whereAID='"+AID+"'andatype='"+type+"'";row=stmt.executeUpdate(sql);row=row*row;}}else{out.print("<tr><tdbgcolor='#FFFFFF'colspan='5'>请做出选择后再按提交!即将返回上一层页面...</td></tr>");response.setHeader("refresh","2;URL=manage.jsp");}stmt.close();conn.close();if(row>0){out.print("<tr><tdbgcolor='#FFFFFF'colspan='5'>处理成功!即将返回上一层页面...</td></tr>");response.setHeader("refresh","1;URL=manage.jsp");}}catch(Exceptione){out.print("提交失败!将返回上一层页面...");e.printStackTrace();response.setHeader("refresh","2;URL=manage.jsp");}%></body></html>