av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

使用displaytag實(shí)現(xiàn)數(shù)據(jù)庫(kù)分頁(yè)(displaytag數(shù)據(jù)庫(kù)分頁(yè))

在軟件開發(fā)中,經(jīng)常需要對(duì)數(shù)據(jù)庫(kù)進(jìn)行分頁(yè)操作,以便在頁(yè)面上顯示較大數(shù)據(jù)集的一部分,這樣可以提高頁(yè)面加載速度,并且也有助于減輕服務(wù)器的壓力。 displaytag是一種在Java應(yīng)用程序中實(shí)現(xiàn)分頁(yè)顯示數(shù)據(jù)的流行工具。在本文中,我們將介紹如何使用displaytag來(lái)實(shí)現(xiàn)數(shù)據(jù)庫(kù)分頁(yè)。

步驟1:使用Eclipse創(chuàng)建Java Web應(yīng)用程序

我們需要?jiǎng)?chuàng)建一個(gè)Java Web應(yīng)用程序,在Eclipse中可以輕松實(shí)現(xiàn)。在Eclipse菜單中選擇File -> New -> Other -> Web -> Dynamic Web Project,然后提供一個(gè)項(xiàng)目名稱和目標(biāo)運(yùn)行時(shí)環(huán)境(比如Tomcat),單擊下一步。

在項(xiàng)目設(shè)置對(duì)話框中,選擇Target Runtime(如Apache Tomcat v9.0),并選擇Dynamic web module版本(如4.0),接著點(diǎn)擊下一步。

在Web module設(shè)置對(duì)話框中,設(shè)置上下文根(這是Web應(yīng)用程序在Tomcat中URL地址)及頁(yè)面存儲(chǔ)目錄。單擊完成,我們已成功創(chuàng)建了Java Web應(yīng)用程序。

步驟2:連接到數(shù)據(jù)庫(kù)

為了,我們需要先連接到數(shù)據(jù)庫(kù)。在我們的示例代碼中,我們將連接到MySQL數(shù)據(jù)庫(kù)。因此,我們需要在Web應(yīng)用程序中的lib目錄中添加MySQL數(shù)據(jù)庫(kù)連接器(mysql-connector-java-8.0.11.jar或更高版本)。然后,我們需要在項(xiàng)目的web.xml文件中添加以下配置:

“`

DB Connection

jdbc/dbconn

javax.sql.DataSource

Contner

DB Connection

jdbc/dbconn

javax.sql.DataSource

“`

接下來(lái),我們就需要在Tomcat的conf目錄的context.xml文件中添加以下代碼:

“`

auth=”Contner”

type=”javax.sql.DataSource”

username=”USERNAME”

password=”PASSWORD”

driverClassName=”com.mysql.jdbc.Driver”

url=”jdbc:mysql://localhost:3306/DBNAME”/>

“`

在這里,我們需要將USERNAME和PASSWORD替換為數(shù)據(jù)庫(kù)的用戶名和密碼,同時(shí)將DBNAME替換為數(shù)據(jù)庫(kù)名稱。

步驟3:創(chuàng)建數(shù)據(jù)庫(kù)表并添加數(shù)據(jù)

在我們的示例代碼中,我們將創(chuàng)建一個(gè)表,名稱為movies,表結(jié)構(gòu)如下:

“`

CREATE TABLE movies (

id INT NOT NULL AUTO_INCREMENT,

title VARCHAR(255) NOT NULL,

director VARCHAR(255) NOT NULL,

release_year INT NOT NULL,

PRIMARY KEY (id)

);

“`

接著,我們將添加一些測(cè)試數(shù)據(jù):

“`

INSERT INTO movies (title, director, release_year) VALUES (“The Shawshank Redemption”, “Frank Darabont”, 1994);

INSERT INTO movies (title, director, release_year) VALUES (“The Godfather”, “Francis Ford Coppola”, 1972);

INSERT INTO movies (title, director, release_year) VALUES (“The Godfather: Part II”, “Francis Ford Coppola”, 1974);

INSERT INTO movies (title, director, release_year) VALUES (“The Dark Knight”, “Christopher Nolan”, 2023);

INSERT INTO movies (title, director, release_year) VALUES (“12 Angry Men”, “Sidney Lumet”, 1957);

INSERT INTO movies (title, director, release_year) VALUES (“Schindler’s List”, “Steven Spielberg”, 1993);

INSERT INTO movies (title, director, release_year) VALUES (“Pulp Fiction”, “Quentin Tarantino”, 1994);

INSERT INTO movies (title, director, release_year) VALUES (“The Lord of the Rings: The Fellowship of the Ring”, “Peter Jackson”, 2023);

INSERT INTO movies (title, director, release_year) VALUES (“Forrest Gump”, “Robert Zemeckis”, 1994);

INSERT INTO movies (title, director, release_year) VALUES (“The Empire Strikes Back”, “Irvin Kershner”, 1980);

INSERT INTO movies (title, director, release_year) VALUES (“The Matrix”, “The Wachowski Brothers”, 1999);

“`

步驟4:創(chuàng)建Movie實(shí)體類

為了將數(shù)據(jù)庫(kù)表中的數(shù)據(jù)顯示在Web應(yīng)用程序中,我們需要?jiǎng)?chuàng)建Movie實(shí)體類。該類的代碼如下:

“`

public class Movie {

private int id;

private String title;

private String director;

private int releaseYear;

public int getId() {

return id;

}

public void setId(int id) {

this.id = id;

}

public String getTitle() {

return title;

}

public void setTitle(String title) {

this.title = title;

}

public String getDirector() {

return director;

}

public void setDirector(String director) {

this.director = director;

}

public int getReleaseYear() {

return releaseYear;

}

public void setReleaseYear(int releaseYear) {

this.releaseYear = releaseYear;

}

}

“`

步驟5:編寫MovieDao類

接下來(lái),我們需要?jiǎng)?chuàng)建一個(gè)MovieDao類,該類用于從數(shù)據(jù)庫(kù)中獲取Movie實(shí)例。類的代碼如下:

“`

public class MovieDao {

private Connection con;

public MovieDao() {

try {

Context ctx = new InitialContext();

DataSource ds = (DataSource) ctx.lookup(“java:/comp/env/jdbc/dbconn”);

con = ds.getConnection();

}

catch (NamingException | SQLException e) {

e.printStackTrace();

}

}

public List getMovies(int startIndex, int length) throws SQLException {

List list = new ArrayList();

String sql = “SELECT * FROM movies LIMIT ?, ?”;

PreparedStatement stmt = con.prepareStatement(sql);

stmt.setInt(1, startIndex);

stmt.setInt(2, length);

ResultSet rs = stmt.executeQuery();

while (rs.next()) {

Movie m = new Movie();

m.setId(rs.getInt(“id”));

m.setTitle(rs.getString(“title”));

m.setDirector(rs.getString(“director”));

m.setReleaseYear(rs.getInt(“release_year”));

list.add(m);

}

rs.close();

stmt.close();

return list;

}

public int getMoviesCount() throws SQLException {

String sql = “SELECT COUNT(*) FROM movies”;

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery(sql);

rs.next();

int count = rs.getInt(1);

rs.close();

stmt.close();

return count;

}

}

“`

在這個(gè)類中,我們首先通過(guò)JNDI連接到我們的MySQL數(shù)據(jù)庫(kù)。然后,我們編寫getMovies和getMoviesCount方法,用于從movies表中獲取電影數(shù)據(jù)和電影數(shù)量數(shù)據(jù)。

步驟6:編寫Movies.jsp頁(yè)面

我們需要編寫Movies.jsp頁(yè)面,并使用displaytag來(lái)實(shí)現(xiàn)數(shù)據(jù)庫(kù)分頁(yè)。頁(yè)面的代碼如下:

“`

List of Movies

List of Movies

<%

try {

int currentPage = request.getParameter(“page”) != null ? Integer.parseInt(request.getParameter(“page”)) : 1;

int startIndex = (currentPage – 1) * 5;

MovieDao dao = new MovieDao();

List movies = dao.getMovies(startIndex, 5);

int totalRows = dao.getMoviesCount();

pageContext.setAttribute(“movies”, movies);

pageContext.setAttribute(“totalRows”, totalRows);

}

catch (SQLException e) {

e.printStackTrace();

}

%>

“`

在這個(gè)頁(yè)面中,我們首先導(dǎo)入了MovieDao和Movie實(shí)體類。然后,我們使用displaytag來(lái)顯示movies表中的電影數(shù)據(jù)。我們?cè)O(shè)置了pagesize為5,表示每頁(yè)顯示5條數(shù)據(jù)。在表格之下,我們使用display:pagination來(lái)顯示分頁(yè)導(dǎo)航欄。

在頁(yè)面上方,我們使用P腳本并調(diào)用MovieDao來(lái)獲取電影數(shù)據(jù)。我們首先嘗試從請(qǐng)求參數(shù)中獲取當(dāng)前頁(yè)數(shù),如果為空,則默認(rèn)為之一頁(yè)。我們?cè)O(shè)置startIndex為每頁(yè)顯示5條數(shù)據(jù)的起始索引。然后,我們調(diào)用MovieDao的getMovies和getMoviesCount方法,分別獲取movies表中的電影數(shù)據(jù)和電影數(shù)量數(shù)據(jù)。我們使用pageContext.setAttribute方法將數(shù)據(jù)存儲(chǔ)在pageContext中,以便在displaytag表格中使用。

結(jié)論

成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián)為您提供網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)頁(yè)設(shè)計(jì)及定制高端網(wǎng)站建設(shè)服務(wù)!

struts分頁(yè)顯示問(wèn)題

建議LZ換中仿隱思路,采用displayTag標(biāo)簽來(lái)實(shí)現(xiàn)吧

你可以先嘗試下

這上面的小程序案例,你會(huì)發(fā)現(xiàn)displayTag標(biāo)櫻猜簽很強(qiáng)備頌廳大…

把你的值方在request 或塵毀者session屬性帆陪中 action里 用 getAttribute()方法

百度的分頁(yè)派轎備就是問(wèn)號(hào)傳參的

displaytag 數(shù)據(jù)庫(kù)分頁(yè)的介紹就聊到這里吧,感謝你花時(shí)間閱讀本站內(nèi)容,更多關(guān)于displaytag 數(shù)據(jù)庫(kù)分頁(yè),使用displaytag實(shí)現(xiàn)數(shù)據(jù)庫(kù)分頁(yè),struts分頁(yè)顯示問(wèn)題的信息別忘了在本站進(jìn)行查找喔。

香港云服務(wù)器機(jī)房,創(chuàng)新互聯(lián)(www.cdcxhl.com)專業(yè)云服務(wù)器廠商,回大陸優(yōu)化帶寬,安全/穩(wěn)定/低延遲.創(chuàng)新互聯(lián)助力企業(yè)出海業(yè)務(wù),提供一站式解決方案。香港服務(wù)器-免備案低延遲-雙向CN2+BGP極速互訪!


本文標(biāo)題:使用displaytag實(shí)現(xiàn)數(shù)據(jù)庫(kù)分頁(yè)(displaytag數(shù)據(jù)庫(kù)分頁(yè))
文章出自:http://uogjgqi.cn/article/djooddc.html
掃二維碼與項(xiàng)目經(jīng)理溝通

我們?cè)谖⑿派?4小時(shí)期待你的聲音

解答本文疑問(wèn)/技術(shù)咨詢/運(yùn)營(yíng)咨詢/技術(shù)建議/互聯(lián)網(wǎng)交流