<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="com.sushe.bean.Sushe"%>
<%@ page import="com.sushe.bean.Weisheng"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">   
    <title>My JSP 'weisheng.jsp' starting page</title>
  </head>
  
  <body>
   <jsp:useBean id="db15" class="com.sushe.conn.SushehaoSql" scope="page"></jsp:useBean>
   <jsp:useBean id="db16" class="com.sushe.conn.WeishengSql" scope="page"></jsp:useBean>
  <jsp:useBean id="sushe" class="com.sushe.bean.Sushe" scope="page"></jsp:useBean>
  卫生分数录入 <br>
   第一次 <br>
 <%
List<Sushe> sushehaolist=db15.queryAllSushehao();

//String[] sushehao=null;
int size=sushehaolist.size();
    if(sushehaolist!= null && size!= 0){
        for(int i = 0; i< size;i++){       
        %>
<form action="" name="" method="post">
<%=sushehaolist.get(i).getSushehao()%>号宿舍
<input type="text" name="score" value=""><br>
<%
//if(null!=request.getParameterValues("score")&&null!=request.getParameterValues("sushehaolist.get(i).getSushehao()"))
//{
//sushehao[i]=sushehaolist.get(i).getSushehao();
String[] sushehao=request.getParameterValues("sushehaolist.get(i).getSushehao()");
String[] score=request.getParameterValues("score");
Weisheng s=new Weisheng(); //实例化类的对象
List<Weisheng> weishenglist=db16.updateWeisheng(score,sushehao);
if(weishenglist.size()>0){
out.print("  更新成功");
}
else{
out.print("  更新失败");}
}
}
//}
%>
<input type="submit" name="mysubmit" value="提交">
</form>
  </body>
</html>java类 public List<Weisheng> updateWeisheng(String[] score,String[] sushehao){
List<Weisheng> weishenglist=new ArrayList<Weisheng>();
int flag1=0;
System.out.print("分数"+score);
System.out.print("宿舍号"+sushehao);
String sql1="select count(*) from t_sushe";
String sql="update t_weisheng set one=? where sushehao=?"; try {
conn=db.getConn();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
     try {
     pstat=conn.prepareStatement(sql1);
     rs=pstat.executeQuery();
     while(rs.next()){
     System.out.print("结果"+rs.getInt(1)+"///");
     pstat=conn.prepareStatement(sql);
        
    
    
         for(int i=0;i<rs.getInt(1);i++){
               int flag=0;
               //System.out.print(score[i].toString());
               //System.out.print(sushehao[i]);
               
               pstat.setString(1,score[i].toString());
               pstat.setString(2,sushehao[i]);
               //pstat.addBatch();
               //pstat.executeBatch();
               flag=pstat.executeUpdate();
               if(flag>0){
                flag1++;
               }
             if(flag==rs.getInt(1)){
           //return true;
           }
             }
         db.closeConn(conn);
     }
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return weishenglist;
}但是不对,数组没传过去吧

解决方案 »

  1.   

    如果宿舍号是
    1,2,3,4
    分数是
    100,90,90,80
    这样的
    那么就是分别拆分成数组,然后一个FOR循环的样子,循环的次数就是数组的长度
    注意替换掉传过来的时候可能出现的空格即可。
      

  2.   

    能不能写点儿代码呢 说的太抽象了  哎  本人对jsp也不精通啊 谢谢
      

  3.   

     <%
    List<Sushe> sushehaolist=db15.queryAllSushehao(); int size=sushehaolist.size();
     for(int i = 0; i< size;i++){  
      sushe=sushehaolist.get(i);
      %>
      <form action="" name="" method="post">
    <input type="text" name="sushehao" value="<%=sushe.getSushehao()%>">号宿舍
    <input type="text" name="score" value=""><br>  
      <% 
    if(sushehaolist!=null&&request.getParameterValues("score")!=null&&request.getParameterValues("sushehao")!=null){
    String[] score=request.getParameterValues("score");
    String[] sushehao=request.getParameterValues("sushehao");
    System.out.print("宿舍号"+sushehao);
    System.out.print("分数"+score);
      List<Weisheng> weishenglist=db16.updateWeisheng(score,sushehao);
      if(weishenglist!=null){
      int size1=weishenglist.size();
      }
    }
    }%>
    控制台输出宿舍号[Ljava.lang.String;@152482a分数[Ljava.lang.String;@fff578什么错误呢  怎么改 谢谢