Java 检索时无法获取0位置上表中的第一个元素?

Java 检索时无法获取0位置上表中的第一个元素?,java,mysql,hibernate,Java,Mysql,Hibernate,这是我的jsp页面 <%@page import="java.util.List"%> <%@page import="org.hibernate.cfg.Configuration"%> <%@page import="org.hibernate.Session"%> <%@page import="org.hibernate.SessionFactory"%> <%@page contentType

这是我的jsp页面

    <%@page import="java.util.List"%>
    <%@page import="org.hibernate.cfg.Configuration"%>
    <%@page import="org.hibernate.Session"%>
    <%@page import="org.hibernate.SessionFactory"%>
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
      <% 
    SessionFactory sessionfactory=null;
    Session Listsession=null ;
    sessionfactory=new Configuration().configure().buildSessionFactory();
     Listsession = sessionfactory.openSession();
          String name="";
          String age="";
          String address="";
          String phone_no="";
      try
    {
      int c=0;
     if(request.getAttribute("c")!=null)
    {

      c=Integer.parseInt(request.getAttribute("c").toString());
       }

        org.hibernate.Query query=Listsession.createQuery("select name,age,address,phone_number from paging order by auto_inc"); 
       query.setFirstResult(c);
       query.setMaxResults(10);
        List check1 =query.list();
       java.util.Iterator on=check1.iterator();
        while(on.hasNext())
         {
        Object oo[]=(Object[])on.next();

            name=(String)oo[0].toString().trim();
            age=(String)oo[1].toString().trim();
            address=(String)oo[2].toString().trim();
            phone_no=(String)oo[3].toString().trim();


              %>
           <div align="center" style="border-bottom:1px solid #ccc "> Name &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="text" value="<%=name %> " disabled="disabled">
    <br><br>

            </div>
               <%        }

                     }       
             catch(Exception ee){
            out.print(ee.getMessage());

             }
          %>

          <center>  <img src="fgfdg.png"> </center>
            <table align="center">
             <tr>
              <td><a href="Pagecount?c=0">First Page</a></td>
              <%
           int value_counter=0;
           int pagecount=0;
              long counters=0;
               try{
              org.hibernate.Query query=Listsession.createQuery("select count(*) from paging order by auto_inc"); 

            List check1 =query.list();
                java.util.Iterator on=check1.iterator();
            while(on.hasNext())
              {
              Object oo=on.next();

                counters=((Number)oo).longValue();


                    }}

             catch(Exception e)
              {
              out.println(e);
                  }  

              int count=(int)counters/10; 
              int Counter_in_int=count*10;
             double xyz=Counter_in_int-counters;
               if(xyz>=0)
               {
               for(int i=0;i<count;i++)
              {

                   pagecount++; 
                %>  
             <td><a href="Pagecount?c=<%=value_counter %>"><%= pagecount%></a></td> 
             <% value_counter=value_counter+10;} }
             else
              {
                   %>

             <%
                for(int i=0;i<=count;i++)
                 {
                  pagecount++; 
               %> 
                 <td><a href="Pagecount?c=<%=value_counter %>"><%= pagecount%></a></td>          
               <% value_counter=value_counter+10;} }
                  %>
           <td><a href="Pagecount?c=<%=value_counter-10 %>">Last Page</a></td>
            </tr>
           </table>

        </body>
           </html>
数据库包含30条记录:

Name

Tom
Mary
Martha
Angelina
Joe
Gordon
Kim
Steve
Kristen
John
Mike
Smith
Daniel
Sheamus
Vince
Longbottom
Harry
Hermione
Ron
Peter
Sammy
Fitzgerald
Leonardo
Ben
Bruce
Jude
Richie
Kate
William
Ron
运行此页面后,我在每页上得到10个结果。我知道,在MySQL中插入数据时,我们将其插入第一个位置(MySQL中的索引从1开始),但在检索数据时,MySQL第一个索引上的数据位于列表中的索引0上

所以我的问题是-
上面的代码是如何正常工作的,因为它在第一页打印的是来自
“Tom”到“John”,即数据库中的前10条记录,但现在当我单击第2页时,c设置为10,它再次从“Mike”到“Peter”打印记录,但它应该从“John到Ron”打印,因为John在数组中处于第10位。

我可以看出,它正在打印预期结果。第一个索引是0,因此索引为10的元素是第十一个,与“Mike”对应。

请不要使用scriplets!看看MVC模型2:@Anton Hey man我不明白你给我的链接,你能告诉我在上面的代码中我可以用什么来代替scriplets吗?我在想JSTL,但没有JSTL和scriplet,我怎么能在JSP页面中编写java代码。你得到了“Ron”谢谢你给我答案,你能告诉我除了JSTL和scriplets之外,还有什么方法可以操作jsp页面或在jsp页面中编写java代码吗。
Name

Tom
Mary
Martha
Angelina
Joe
Gordon
Kim
Steve
Kristen
John
Mike
Smith
Daniel
Sheamus
Vince
Longbottom
Harry
Hermione
Ron
Peter
Sammy
Fitzgerald
Leonardo
Ben
Bruce
Jude
Richie
Kate
William
Ron