?? changeshoppic.jsp
字號:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="errorpage.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>無標題文檔</title>
<style type="text/css">
<!--
.STYLE3 {color: #FFFFFF; font-weight: bold; }
.STYLE2 {color: #FFFFFF}
.STYLE6 {font-size: 10px}
.STYLE7 {font-size: 10; }
body,td,th {
font-size: 12px;
}
a:link {
text-decoration: none;
}
a:visited {
text-decoration: none;
}
a:hover {
text-decoration: none;
}
a:active {
text-decoration: none;
}
-->
</style>
</head>
<link href="mycss.css" rel="stylesheet" type="text/css" />
<jsp:useBean id="db" class="data.DBConnectionBean"/>
<%!
int PageSize =1; //設置每張網頁顯示兩筆記錄
int ShowPage = 1; //設置欲顯示的頁數
int RowCount = 0; //ResultSet的記錄筆數
int PageCount = 0; //ResultSet分頁后的總頁數
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
public void jspInit() //執行數據庫與相關數據的初始化
{
try{
Class.forName("org.gjt.mm.mysql.Driver");
//使用DriverManager類的getConnection()方法建立聯接,
con = DriverManager.getConnection
("jdbc:mysql://localhost:3306/mydb","root","test");
//建立Statement對象, 并設置記錄指標類型為可前后移動
stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
rs = stmt.executeQuery("SELECT * FROM shoppic order by zjtime"); //建立ResultSet(結果集)對象,并執行SQL語句
rs.last(); //將指標移至最后一筆記錄
RowCount = rs.getRow(); //取得ResultSet中記錄的筆數
//計算顯示的頁數
PageCount = ((RowCount % PageSize) == 0 ?
(RowCount/PageSize) : (RowCount/PageSize)+1);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
public void jspDestroy() //執行關閉各種對象的操作
{
try{
rs.close(); //關閉ResultSet對象
stmt.close(); //關閉Statement對象
con.close(); //關閉數據庫鏈接對象
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
%>
<body>
<table width="626" border="1" align="left" cellspacing="0" bordercolor="#ECE9D8">
<tr>
<td width="620" bgcolor="#996666"> </td>
</tr>
<tr>
<td height="180"><table width="620" height="161" border="1" align="center" cellspacing="0" bordercolor="#993300">
<tr>
<td height="16" colspan="2" bgcolor="#993300"><div align="center"><span class="STYLE2">選擇商店圖片。</span></div></td>
</tr>
<tr>
<td width="271" height="109" background="../pic/bbgg.jpg"><table width="269" border="0" align="center" cellspacing="0">
<tr>
<td><div align="center" class="STYLE6">
<%
String ToPage = request.getParameter("ToPage");
if(ToPage != null) //判斷是否可正確取得ToPage參數
{
ShowPage = Integer.parseInt(ToPage); //取得指定顯示的分頁頁數
if(ShowPage > PageCount) //下面的if語句將判斷用戶輸入的頁數是否正確
{
ShowPage = PageCount; //判斷指定頁數是否大于總頁數, 是則設置顯示最后一頁
}
else if(ShowPage <= 0)
{
ShowPage = 1; //若指定頁數小于0, 則設置顯示第一頁的記錄
}
}
rs.absolute((ShowPage - 1) * PageSize + 1); //計算欲顯示頁的第一筆記錄位置
%>
<H3>
當前在第<font color = "red"> <%= ShowPage %></font>頁, 共 <font color = "red"> <%= PageCount %></font>頁
<%
//利用For循環配合PageSize屬性輸出一頁中的記錄
for(int i = 1; i <= PageSize; i++)
{
%>
</div></td>
</tr>
<tr>
<td height="59"><table width="122" height="63" border="1" align="center" cellspacing="0" bordercolor="#996666">
<tr>
<td width="80"><img src="../shoppic/<%=rs.getString("pic_url")%>" width="80" height="80" /></td>
<td width="32"><a href="soldshop.jsp?head=<%=rs.getString("pic_url")%>">選擇</a></td>
</tr>
</table></td>
</tr>
<tr>
<td><p align="center">
<%
//下面的if判斷語句用于防止輸出最后一頁記錄時,
//將記錄指標移至最后一筆記錄之后
if(!rs.next()) //判斷是否到達最后一筆記錄
break; //跳出for循環
}
%>
</p>
<table width="269">
<tr valign="baseline" align="center">
<%
//判斷目前所在分頁是否為第一頁,
//不是則顯示到第一頁與上一頁的超鏈接
if(ShowPage != 1)
{
//下面建立的各超鏈接將鏈接至自己,
//并將欲顯示的分頁以ToPage參數傳遞給自己
%>
<td width="150" height="23"><a href="changeshoppic.jsp?ToPage=<%= 1 %>" class="STYLE7">首頁</a> </td>
<td width="150"><a href="changeshoppic.jsp?ToPage=<%= ShowPage - 1 %>" class="STYLE7"><</a> </td>
<%
}
//判斷目前所在分頁是否為最后一頁,
//不是則顯示到最后一頁與下一頁的超鏈接
if(ShowPage != PageCount)
{
//下面建立的各超鏈接將鏈接至自己,
//并將欲顯示的分頁以ToPage參數傳遞自己
%>
<td width="150"><a href="changeshoppic.jsp?ToPage=<%= ShowPage + 1%>" class="STYLE7">></a> </td>
<td width="150"><a href="changeshoppic.jsp?ToPage=<%= PageCount %>" class="STYLE7">末頁</a> </td>
<%
}
%>
<td width="150"><form action="changeshoppic.jsp" method="post" class="STYLE7">
到
<input type="text" name="ToPage" style="HEIGHT: 15px; WIDTH: 20px"
value="<%= ShowPage%>" />
頁
</form></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="324" background="../pic/bbgg.jpg"><p align="center">自定義頭像上傳.上傳后再選擇</p>
<p align="center">格式為jpg,gif,bmp,png否則無法顯示!</p>
<form action="picup.jsp" method="post"
enctype="multipart/form-data" name="product" id="product">
<table border="1" align="center" cellspacing="1">
<tr>
<td width="85"><p class="style2"> 上傳圖片</p></td>
<td width="279"><input type="file" name="FILE1" size="30" />
</td>
</tr>
<tr>
<td colspan="2" align="right"><div align="center">
<input name="upload" type="submit" value="提交" />
</div></td>
</tr>
</table>
</form></td>
</tr>
<tr>
<td height="16" colspan="2" background="../pic/bbgg.jpg"> </td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -