Sencha Touch for paging

Source: Internet
Author: User

The parameters passed from the client are: Limit,start

Service-Side code:

<%@ page language= "java" import= "java.util.*" pageencoding= "Utf-8"%><% @page import= "Java.sql.SQLException" %><% @page import= "Java.sql.DriverManager"%><% @page import= "java.sql.Connection"%><% @page Import = "Java.sql.PreparedStatement"%><% @page import= "Java.sql.ResultSet"%><% @page import= " Com.gr.jiang.json.JsonString "%><%string path = Request.getcontextpath (); String basepath = request.getscheme () + "://" +request.getservername () + ":" +request.getserverport () +path+ "/";%> <%connection con = null; ResultSet set = null; PreparedStatement pre = NULL;  try{class.forname ("Com.mysql.jdbc.Driver"). newinstance ();  String url = "Jdbc:mysql://localhost:3306/news_mobile";    con = drivermanager.getconnection (URL, "root", "Jiang");  int pagecount = 0;  String SEL = "SELECT * FROM books limit?,?";  String COU = "Select COUNT (*) from books";  Pre = Con.preparestatement (SEL);  Pre.setint (1,integer.parseint (Request.getparameter ("Start")); Pre.setint (2,integer.parseint (Request.getparameter ("limit"));  Set = Pre.executequery ();    int count = 0;  jsonstring json = new jsonstring ();  String str = "["; while (Set.next ()) {str + = "{\" id\ ": \" "+set.getint (" id ") +" \ ", \" image_url\ ": \" "+set.getstring (" Image_url ") +" \ ", \" book_name\ ": \" "+set.getstring (" book_name ") +" \ ", \" author\ ": \" "+set.getstring (" author ") +" \ ", \" Descri     ption\ ": \" "+set.getstring (" description ") +" \ "},";      Json.start ();      Json.setjson ("id", Set.getint ("id"));      Json.setjson ("Image_url", Set.getstring ("Image_url"));      Json.setjson ("Book_name", Set.getstring ("Book_name"));      Json.setjson ("Author", Set.getstring ("author"));      Json.setjson ("description", set.getstring ("description"));      Json.end ();  Count = Set.getrow ();  } str = str.substring (0,str.length ()-1) + "]";  System.out.println (str);  Pre = Con.preparestatement (COU);   Set = Pre.executequery ();      Set.next (); PageCount = SET.getint (1);  if (Count > 0) {out.println ("{\" success\ ": \" true\ ", \" bookcount\ ": \" "+pagecount+" \ ", \" books\ ":" +str+ "}");  } else {out.println ("{\" success\ ": \" false\ ", \" message\ ": \" failed to read data \ "}");     }}catch (SQLException e) {out.println ("{\" success\ ": \" false\ ", \" message\ ": \" read data failed \ "}"); E.printstacktrace ();     }finally{Set.close ();     Pre.close ();      Con.close (); }%>
Client App.js:

Ext.require ([' Ext.data.Store ', ' Ext.data.reader.Json ', ' Ext.dataview.DataView ']) ext.application ({name: ' Myap P ', Icon: ' Images/icon.png ', Glossonicon:false, Phonestartupscreen: ' Images/phone_startup.png ', Tabletstartup Screen: ' Images/tablet_startup.png ', launch:function () {ext.define (' BookInfo ', {extend: ' Ext.data . Model ', config:{fields:[' Image_url ', ' book_name ', ' author ', ' Description '}})        ; var bookreader=ext.create (' Ext.data.reader.Json ', {type: ' Json ', Rootproperty: ' Books ', t        Otalproperty: ' Bookcount '}); var pagecount;//page var bookstore=ext.create (' Ext.data.Store ', {autoload:true, model: ' BookInfo                ', Proxy: {type: ' ajax ', url: ' http://10.65.9.223:8080/news_mobile/json.jsp ', Reader:bookreader}, Pagesize:5, Scope:this,           Listeners: {load:function (store,records,successful,operation) {                            Read data failure if (!successful)//Eject error message Ext.Msg.alert (                    This.getproxy (). Getreader (). Rawdata.message);                        else {var recordcount=bookreader.rawdata[bookreader.gettotalproperty ()];                        var pagesize=this.getpagesize ();                        Pagecount= (recordcount-recordcount%pagesize)/pagesize;                        if (recordcount%pagesize>0) pagecount+=1;                        EXT.GETCMP (' PageInfo '). SetText (String (this.currentpage) + "/" +pagecount+ "page"                    );        }                }            }        });        var toolbar =ext.create (' Ext.toolbar ', {docked: ' Bottom ',      Width: ' 100% ', layout:{type: ' Hbox ', pack: ' Center '}, Items: [{iconmask:true, iconcls: ' FirstPage ', handler:funct                Ion () {bookstore.loadpage (1); }}, {iconmask:true, iconcls: ' Arrow_left ', Handler:fu Nction () {if (bookstore.currentpage>1) {bookstore.previous                    Page ();                }}}, {iconmask:true, iconcls: ' Arrow_right ',                        Handler:function () {if (Bookstore.currentpage<pagecount) {                    Bookstore.nextpage ();                }}}, {iconmask:true, iconcls: ' LastPage ', HAndler:function () {bookstore.loadpage (PageCount);            }}, {html: ', Style: ' font-size:16px ', id: ' PageInfo '                }]        }); var booktemplate=new ext.xtemplate (' <tpl for= '. > ', ' <div class= ' book_img ' ></div> ', ' <            Div class= "Book_info" > ', ' 

HTML <! DOCTYPE html>



Sencha Touch for paging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.