原来有个软件,用ASP做的,一个页面,一下子返回几百行记录,比较快我现在用JSP,一下子返回几百行,就很慢,为什么?有办法提高吗?还是TOMCAT就是很慢还有,操作那个一下子返回几百行的记录的页面,如果连续操作该页面,会导致服务器短暂瘫痪,1分钟左右难道TOMCAT性能远不如IIS??

解决方案 »

  1.   

    个人觉得这个跟tomcat关系不大,而是你程序读取数据库信息的程序实现效率的问题,也就是JDBC实现的问题,如果用了hibernate那可能是 hibernate没有优化的原因
      

  2.   

    我试过一次返回几行,十几行,就没问题没有用HIBERNATE<%
       String name="";
       String post="";
       String sex="";
       String birthday="";
       String education="";
       String policelevel="";
       String policerank="";
       String mobile="";
       String policenum="";
    //   String depid="";
       String depname="";
       String postname="";
     
           String postview="";
       String orderid="";               if(depids!=null)
       sql="select depid,post,policenum,id, name,sex,birthday,education,postlevel,policerank,mobile from police   where depid='"+depids+"' order by hiddenpost";
      if(depids==null||(depids!=null&&depids.equals("")))
                   sql="select depid,post,policenum,id, name,sex,birthday,education,postlevel,policerank,mobile from police  order by depid,hiddenpost ";
           //    ResultSet rs=null;        // out.println(sql);    ResultSet rs1=null;

       rs=s_item.executeQuery(sql);    while(rs!=null&&rs.next()){
       postview="";
       depid=rs.getString("depid");
       post=rs.getString("post");
       policenum=rs.getString("policenum");
       id=rs.getString("id");    String sql1="select *  from department where id="+depid;
       rs1=s_item.executeQuery(sql1);
       if(rs1!=null&&rs1.next())
       depname=rs1.getString("depname");    if(rs1!=null)

       rs1.close();
        s_item.closeStmt();
                    s_item.closeConn();
          i=0;
                      name=rs.getString("name");
    //  post=rs.getString("post");

      sex=rs.getString("sex");
      birthday=rs.getString("birthday");
      education=rs.getString("education");
      policelevel=rs.getString("postlevel");
      policerank=rs.getString("policerank");
      mobile=rs.getString("mobile");
     // policenum=rs.getString("policenum");                 //   out.println(inside.length());
     if(sex==null||(sex!=null&&sex.equals(" ")))

         sex="&nbsp;";
     if(birthday==null||(birthday!=null&&birthday.equals("1900-01-01 00:00:00.0")))
      birthday="&nbsp;";
     else
     birthday=birthday.substring(0,10);

     if(education==null||(education!=null&&education.equals("")))
     education="&nbsp;";
     if(policelevel==null||(policelevel!=null&&policelevel.equals("")))
     policelevel="&nbsp;";
     if(policerank==null||(policerank!=null&&policerank.equals("")))
     policerank="&nbsp;";
     if(mobile==null||(mobile!=null&&mobile.equals("")))
     mobile="&nbsp;";
      if(post==null||(post!=null&&post.equals("")))
     post="&nbsp;";
                      //  out.println(birthday);                 %>

                                       <tr class="tdbg">
       <td align="center" height="27"><%=depname%></td>
       
         <td align="center"><a href="#" onclick="openwin1(<%=policenum%>)"><%=name%></a></td>
      <td align="center" height="27"><%=post%></td>
     <td align="center"><%=policelevel%></td>
         <td align="center" height="27"><%=sex%></td>
         <td align="center"><%=birthday%></td>
     <td align="center"><%=education%></td>
         <td align="center" height="27"><%=policenum%></td>
         <td align="center"><%=policerank%></td>
     <td ><%=mobile%></td>
                                 <%
     if(depids==null||(depids!=null&&depids.equals(""))){
     %>
      <td ><font size=2px><a href="#" onclick="openwin1(<%=id%>)">查看</a> <a href="#" onclick="openwin3(<%=id%>)">修改</a> <a href="#" onclick="openwin4(<%=id%>)"> 删除 </a><a href="#" onclick="openwin2(<%=id%>,'move')">调动</a> <a href="#" onclick="openwin2(<%=id%>,'punish')">奖惩</a> <a href="#" onclick="openwin2(<%=id%>,'leave')">请假</a></font></td>
      <%
     }
     else{
     %>
       <td ><font size=2px><a href="#" onclick="openwin1(<%=id%>)">查看</a> <a href="#" onclick="openwin3(<%=id%>)">修改</a> <a href="#" onclick="openwin4(<%=id%>)"> 删除 </a><a href="totalorder.jsp?action=up&&id=<%=id%>&&depid=<%=depids%>">上移</a> <a href="totalorder.jsp?action=down&&id=<%=id%>&&depid=<%=depids%>">下移</a> <a href="#" onclick="openwin2(<%=id%>,'move')">调动</a> <a href="#" onclick="openwin2(<%=id%>,'punish')">奖惩</a> <a href="#" onclick="openwin2(<%=id%>,'leave')">请假</a></font></td>
       <%
     }
     %>
      </tr>
                    <%
       }      if(rs!=null)
        rs.close();
          s_item.closeStmt();
          s_item.closeConn();   %>
      

  3.   

    只能说你写的这个程序实现很挫,让一个JSP页面一下子显示几百行乃至更多数据肯定会很慢,跟tomcat没啥关系
      

  4.   

    那为什么IIS同样一个页面显示几百行,比TOMCAT快很多呢?这不说明TOMCAT,甚至JSP性能低下吗
      

  5.   

    为什么不能回复?但一下子返回几百行,IIS却很快,不说明TOMCAT甚至JSP差劲吗
      

  6.   

    补充下,原来是使用ASP操作ACCESS,是不是特别快?
      

  7.   

    我有俩问题问题1:在while里进行第一次rs1的查询就连接关闭了,第二次又是怎么建立的连接?我没有找到
    问题2:如果while里你每次都建立的连接就相当于在while循环里进行了上百次的连接开启与关闭
    总之也不知道是你括号没复制全还是代码没复制全,我感觉是你这段while写的有问题
      

  8.   

    [Quote=引用 13 楼  的回复:]
    我有俩问题问题1:在while里进行第一次rs1的查询就连接关闭了,第二次又是怎么建立的连接?我没有找到
    问题2:如果while里你每次都建立的连接就相当于在while循环里进行了上百次的连接开启与关闭
    总之也不知道是你括号没复制全还是代码没复制全,我感觉是你这段while写的有问题
    [/Quo
    谢谢你的提醒。问题出在这几行String sql1="select * from department where id="+depid;
    rs1=s_item.executeQuery(sql1);
    if(rs1!=null&&rs1.next())
    depname=rs1.getString("depname");if(rs1!=null)rs1.close();
    s_item.closeStmt();
    s_item.closeConn();我去掉之后,速度快乐很多
      

  9.   

    哥 你的代码 为什么 要在JSP 里面 写 啊,不能在后台写好,然后前台只负责显示吗,你这样严重违背MVC架构,还有你的代码 要深刻的优化,数据库方面的。看到你的代码彻底无语了
      

  10.   

    数据库链接多了自然会慢,可以创建一个conn,然后传递它;后台写数据,前台展现数据多要采用分页方式展现,你一下显示那多数据,客户一条条看?加上搜索条件此外window.open的话也很慢,都注意一下 再者设置一下缓存,