當前位置:首頁 » 操作系統 » jsp頁面顯示資料庫的數據

jsp頁面顯示資料庫的數據

發布時間: 2023-05-30 14:21:19

❶ jsp如何從資料庫中查出數據在頁面上顯示

//查詢所有相片信息 public String selectList(){ List<Baby> result=babyService.getBabys(); ActionContext.getContext().put("result", result); return "babylist"; } jsp顯示 <t:forEach items="${result}" var="item"> <tr> <td>${item.id}</td> <td>${item.name}</td> <td>${item.ntroction}</td> <td>${item.data}</td> <td>${item.commodity}</td> <td>${item.user.id}</td> <td><a href="add_movie.html">查看/修改</a></td> </tr> </t:forEach>

❷ 如何從資料庫中提取數據,在jsp頁面顯示

在資料庫提取部分數據,在JSP上顯示的做法如下:
思路:1、創建db連接 2、創建statement 3、執行查詢 4、遍歷結果並展示
完整代碼如下:
<span style="font-size:12px;"><span style="font-size:14px;"><%@ page language="java" import="java.sql.*,java.io.*,java.util.*"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<style type="text/css">
table {
border: 2px #CCCCCC solid;
width: 360px;
}

td,th {
height: 30px;
border: #CCCCCC 1px solid;
}
</style>
</head>
<body>
<%
//驅動程序名談和
String driverName = "com.mysql.jdbc.Driver";
//資料庫用戶名
String userName = "root";
//密碼
String userPasswd = "szy";
//資料庫名
String dbName = "studentmanage";
//表名
String tableName = "student";
//聯結字元串
String url = "jdbc:mysql://localhost:3306/" + dbName + "?user="
+ userName + "&password=" + userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "SELECT * FROM " + tableName;
ResultSet rs = statement.executeQuery(sql);
%>
<br>
<br>
<table align="center">
<tr>
<th>
<%
out.print("學號");
%>
</th>
<th>
<%
out.print("姓名");
%>
</th>
<th>
<%
out.print("專業");
%>
</th>
<th>
<%
out.print("班級");
%>
</th>
</tr>

<%
while (rs.next()) {
%>
<tr>
<td>
<%
out.print(rs.getString(1));
%>
</td>
<td>
<%
out.print(rs.getString(2));
%>
</td>
<td>
<%
out.print(rs.getString(3));
%>
</td>
<td>
<%
out.print(rs.getString(4));
%>
</td>
</tr>
<%
}
%>
</table>
<div align="center">含告盯
<br> <br> <br>
<%
out.print("數據查詢成功,恭喜你");
%>
<友辯/div>
<%
rs.close();
statement.close();
connection.close();
%>
</body>
</html></span><span style="font-size:24px;color: rgb(255, 0, 0);">
</span></span>

❸ 資料庫的datetime類型數據怎麼顯示到jsp頁面

資料庫的datetime類型數據顯示到jsp頁面的原因:
1、在JSP頁面顯示氏孫族時你就用JSP顯示標簽把他格式一殲弊下就行了。
2、rs.getTimestamp(newTimestamp(time))//rs表示凱態記錄集,time表示你要設置的時間。這樣就可以把java.util.Date類型的時間轉換到資料庫里的時間了。

❹ jsp中如何將資料庫中的數據顯示在頁面中

要想把servlet的數據放到jsp顯示需要做的是:
1.把數據從資料庫里查詢出來,放到結果集里。
2.把結果集放到request中,傳給jsp頁面
3.頁面遍歷結果集顯示即可

❺ 怎麼通過jsp在網頁上把資料庫的數據以表格形式顯示出來

在jsp的body 標簽下,加一個<table></table>標簽。在table標簽差悶裡面,循環取出資料庫的數飢源據,以<tr>標簽展示出來爛慶態。

❻ java從資料庫中讀取的數據怎樣顯示在jsp的網頁當中

創建一個servlet, 在servlet中將數據保存進request。類似request.setAttribute("name", "zhangsan"); ,穗中然後將請求轉發至jsp頁面,在jsp頁面中使用el表達式${requestScope.name}或${name}就可以獲取到顯示燃攔數據。當然皮族胡,也可以使用session。

❼ 在jsp頁面上顯示資料庫一個表中所有的的內容。

在jsp頁面上顯示資料庫一個表中所有的的內容的方法是迭代。
1、jsp頁面接收所有內容的bookslist:
<html>
<body>
<head>
<title>
View Books
</title>
</head>
<body>
<table border=2>
<tr>
<th>Book ID</th>
<th>Title</th>
<th>Author</th>
<th>No. of copies AVAILABLE</th>
<th>Number of favourites</th>
</tr>

<%
ArrayList<Book> dbooks=(ArrayList)request.getAttribute("bookslist");
Iterator it=dbooks.iterator();
while(it.hasNext())
{
Book b=(Book)it.next();
%>
<tr>
<td><%=b.bookID%></td>
<td><%=b.bookTitle%></td>
<td><%=b.bookAuthor%></td>
<td><%=b.bookCopies%></td>
<td><%=b.bookFavs%></td>
</tr>
<%
}
%>
</table>
</body>
</html>

2、java代碼獲取資料庫內容:
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3307/library", "root", "admin");
PreparedStatement ps=con.prepareStatement("select * from book");
ResultSet rs=ps.executeQuery();
ArrayList<Book> books=new ArrayList<Book>();
while(rs.next())
{
Book b= new Book();
b.bookID=rs.getInt(3);
b.bookTitle=rs.getString(1);
b.bookAuthor=rs.getString(2);
b.bookCopies=rs.getInt(4);
b.bookFavs=rs.getInt(5);
books.add(b);
}
req.setAttribute("bookslist",books);
con.close();

❽ 如何在jsp頁面打開時就顯示資料庫數據

原理很簡單,你在jsp頁面頭部寫上 <jsp:forward page="servlet名稱"></jsp:forward> 首先調用這句話的時候要判斷下面的從servlet傳出的數據是否為空,判斷為空一定要用EL表達式,否則就會報錯500,判斷有數據就不要訪問了,因為如果有數據你再訪問就會觸發死循環,只有為空的時候才去訪問servlet名稱,訪問servlet名稱之後就從資料庫取出了你的數據,然後返回到這個頁面顯示,這樣你的數據就成功顯示在頁面上了。

❾ java從資料庫中讀取的數據怎樣顯示在jsp的網頁當中

java從資料庫中讀取的數據顯示在jsp的網頁當中的方法是迭代table。
1、迭代數據的jsp頁面代碼:

<table>
<tr>
<th>Name</th>
<th>Email</th>
<th>Address</th>
<th>Phone No</th>
</tr>
<s:iterator value="users">
<tr>
<td><s:property value="name"/></td>
<td><s:property value="email"/></td>
<td><s:property value="address"/></td>
<td><s:property value="phno"/></td>
</tr>
</s:iterator>
</table>
2。後台java查詢數據
public class RegisterAction extends ActionSupport{
String name,pwd,email,address;
int phno;

public RegisterAction() {}

List<User> users = new ArrayList<User>();
UserDao u = new UserDao();

//Getters and setters.

public String execute() throws Exception {
User u=new User();
u.setName(name);
u.setEmail(email);
u.setAddress(address);
u.setPhno(phno);
u.setPwd(pwd);
u.addUser(u);
return "success";
}

public String listAllUsers(){
users = u.getUsers();
System.out.println("In Action, "+users);
return "success";
}
}

❿ 怎麼從資料庫中提取數據,在jsp頁面顯示

在資料庫提取部分數據,在JSP上顯示的做法如下:
思路:1、創建db連接 2、創建statement 3、執行查詢 4、遍歷結果並展示
完整代碼如下:
<span style="font-size:12px;"><span style="font-size:14px;"><%@ page language="java" import="java.sql.*,java.io.*,java.util.*"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<style type="text/css">
table {
border: 2px #CCCCCC solid;
width: 360px;
}

td,th {
height: 30px;
border: #CCCCCC 1px solid;
}
</style>
</head>
<body>
<%
//驅動程序名
String driverName = "com.mysql.jdbc.Driver";
//資料庫用戶名
String userName = "root";
//密碼
String userPasswd = "szy";
//資料庫名
String dbName = "studentmanage";
//表名
String tableName = "student";
//聯結字元串
String url = "jdbc:mysql://localhost:3306/" + dbName + "?user="
+ userName + "&password=" + userPasswd;
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection = DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql = "SELECT * FROM " + tableName;
ResultSet rs = statement.executeQuery(sql);
%>
<br>
<br>
<table align="center">
<tr>
<th>
<%
out.print("學號");
%>
</th>
<th>
<%
out.print("姓名");
%>
</th>
<th>
<%
out.print("專業");
%>
</th>
<th>
<%
out.print("班級");
%>
</th>
</tr>

<%
while (rs.next()) {
%>
<tr>
<td>
<%
out.print(rs.getString(1));
%>
</td>
<td>
<%
out.print(rs.getString(2));
%>
</td>
<td>
<%
out.print(rs.getString(3));
%>
</td>
<td>
<%
out.print(rs.getString(4));
%>
</td>
</tr>
<%
}
%>
</table>
<div align="center">
<br> <br> <br>
<%
out.print("數據查詢成功,恭喜你");
%>
</div>
<%
rs.close();
statement.close();
connection.close();
%>
</body>
</html></span><span style="font-size:24px;color: rgb(255, 0, 0);">
</span></span>

熱點內容
scratch少兒編程課程 發布:2025-04-16 17:11:44 瀏覽:639
榮耀x10從哪裡設置密碼 發布:2025-04-16 17:11:43 瀏覽:368
java從入門到精通視頻 發布:2025-04-16 17:11:43 瀏覽:84
php微信介面教程 發布:2025-04-16 17:07:30 瀏覽:310
android實現陰影 發布:2025-04-16 16:50:08 瀏覽:793
粉筆直播課緩存 發布:2025-04-16 16:31:21 瀏覽:344
機頂盒都有什麼配置 發布:2025-04-16 16:24:37 瀏覽:212
編寫手游反編譯都需要學習什麼 發布:2025-04-16 16:19:36 瀏覽:812
proteus編譯文件位置 發布:2025-04-16 16:18:44 瀏覽:366
土壓縮的本質 發布:2025-04-16 16:13:21 瀏覽:592