📄 changethingpic.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="addthing.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="changethingpic.jsp?ToPage=<%= 1 %>" class="STYLE7">首页</a> </td>
<td width="150"><a href="changethingpic.jsp?ToPage=<%= ShowPage - 1 %>" class="STYLE7"><</a> </td>
<%
}
//判断目前所在分页是否为最后一页,
//不是则显示到最后一页与下一页的超链接
if(ShowPage != PageCount)
{
//下面建立的各超链接将链接至自己,
//并将欲显示的分页以ToPage参数传递自己
%>
<td width="150"><a href="changethingpic.jsp?ToPage=<%= ShowPage + 1%>" class="STYLE7">></a> </td>
<td width="150"><a href="changethingpic.jsp?ToPage=<%= PageCount %>" class="STYLE7">末页</a> </td>
<%
}
%>
<td width="150"><form action="changethingpic.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="tpicup.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 + -