Summary of JSP website development "8" and jsp website development "8"

Source: Internet
Author: User

Summary of JSP website development "8" and jsp website development "8"

JSP has been summarized into eight articles in this article, with many content, but they are all in practice. This article finally introduces you to a small effect: Baidu paging. That is, when we traverse a large number of data objects, we will see this effect. How does it implement it? Let's take a look at it.

1. Retrieve paging data:

Total number of retrieved data:

public int getSize() {        int num = 0;        Connection conn = null;        Statement st = null;        ResultSet rs = null;        conn = DBO.getConnection();        String sql = "select count(*) from students";        try {            st = conn.createStatement();            rs = st.executeQuery(sql);            rs.next();            num=rs.getInt(1);        } catch (SQLException e) {            e.printStackTrace();        }        return num;    }

The calculation is divided into several pages:

public int getPageCnt(int pageRec) {        int page = 0;        int size = this.getSize();        if(size>0){            page = (size-1)/pageRec+1;        }        return page;    }

Obtain the data to be displayed on this page:

public List<Student> getSome(int pageNo, int pageRec) {        List<Student> list = new ArrayList<Student>();        Connection conn = null;        Statement st = null;        ResultSet rs = null;        try {            conn=DBO.getConnection();            String sql="select * from students limit ";            int num = this.getSize()-pageNo*pageRec;            int a = this.getSize()-(pageNo-1)*pageRec;            if(num<0){                num=0;            }            sql+=(num)+","+ a;            st=conn.createStatement();            rs=st.executeQuery(sql);            while(rs.next()){                Student stu = new Student();                stu.setId(rs.getInt("id"));                stu.setName(rs.getString("username"));                stu.setSex(rs.getInt("sex"));                stu.setYear(rs.getInt("age"));                stu.setFrom(rs.getString("form"));                stu.setSchool(rs.getString("school"));                list.add(stu);            }        } catch (SQLException e) {            e.printStackTrace();        }finally{            DBO.close(rs, st, conn);        }        return list;    }

2. Page effect code:

<% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "errorPage =" error.html "%> <% @ page import =" com. mysql. jsp. student. student "%> <% @ page import =" com. mysql. jsp. sever. studentMaImp "%> <% String path = request. getContextPath (); String basePath = request. getScheme () + ": //" + request. getServerName () + ":" + request. getServerPort () + path + "/"; %> <! Doctype html public "-// W3C // dtd html 4.01 Transitional // EN"> 

:

  

Well, here we can achieve the simplest Baidu paging effect. For specific beautification work, we need our css + div + javascript knowledge. You can learn about it, it is very helpful for Web pages.

Summary of the basic JSP knowledge has been completed for you today. There are 8 blogs in total. Due to the limitation of the text description, I will answer your questions one by one.

After summing up so much, I will talk to you a few words. Before learning JSP, you should try to learn the basic knowledge of JAVASE first, which is very helpful for you to understand the code in JSP, of course, if you are very interested in website development, you can learn HTML and then study JSP. This will help you understand the JSP statements in it. However, it is worth noting that JSP development is far less concerned than PHP development. PHP development does not require much foundation, and JSP development requires a certain JAVA Foundation. If you do not have the JAVA Foundation, we suggest you learn PHP, which can also achieve the development of dynamic websites, and PHP development is very convenient for end-side development, therefore, if you feel a lot of pressure on JSP learning, we suggest you learn PHP. However, when you are new to any technology, you may not understand it. What is important is to stick to it, various technologies are interconnected. When you master a technology and access other technologies, you will get twice the result with half the effort.

Finally, I hope you can find your own blue sky on the road of programmers.

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.