?? browse_0002ejsp_jsp.java
字號:
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;
public class browse_0002ejsp_jsp extends HttpJspBase {
// begin [file="/browse.jsp";from=(11,0);to=(11,52)]
// end
// begin [file="/browse.jsp";from=(12,0);to=(12,78)]
// end
static {
}
public browse_0002ejsp_jsp( ) {
}
private static boolean _jspx_inited = false;
public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
}
public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {
JspFactory _jspxFactory = null;
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
String _value = null;
try {
if (_jspx_inited == false) {
synchronized (this) {
if (_jspx_inited == false) {
_jspx_init();
_jspx_inited = true;
}
}
}
_jspxFactory = JspFactory.getDefaultFactory();
response.setContentType("text/html; charset=GB18030");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// HTML // begin [file="/browse.jsp";from=(0,52);to=(1,0)]
out.write("\r\n");
// end
// HTML // begin [file="/browse.jsp";from=(1,31);to=(2,0)]
out.write("\r\n");
// end
// begin [file="/browse.jsp";from=(2,2);to=(10,0)]
/*檢查客戶是否通過登錄,如果未經過登錄檢查,返回登錄界面。
*驗證用戶是否存在,避免用戶直接進入該頁,以后的每張動態網
*頁都要包括這一部分。*/
if(session.getAttribute("username")==null)
{
response.sendRedirect("login.html");
}
// end
// HTML // begin [file="/browse.jsp";from=(10,2);to=(11,0)]
out.write("\r\n");
// end
// begin [file="/browse.jsp";from=(11,0);to=(11,52)]
book.bk bkId = null;
boolean _jspx_specialbkId = false;
synchronized (pageContext) {
bkId= (book.bk)
pageContext.getAttribute("bkId",PageContext.PAGE_SCOPE);
if ( bkId == null ) {
_jspx_specialbkId = true;
try {
bkId = (book.bk) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "book.bk");
} catch (ClassNotFoundException exc) {
throw new InstantiationException(exc.getMessage());
} catch (Exception exc) {
throw new ServletException (" Cannot create bean of class "+"book.bk", exc);
}
pageContext.setAttribute("bkId", bkId, PageContext.PAGE_SCOPE);
}
}
if(_jspx_specialbkId == true) {
// end
// begin [file="/browse.jsp";from=(11,0);to=(11,52)]
}
// end
// HTML // begin [file="/browse.jsp";from=(11,52);to=(12,0)]
out.write("\r\n");
// end
// begin [file="/browse.jsp";from=(12,0);to=(12,78)]
book.SessionListener SessionListenerId = null;
boolean _jspx_specialSessionListenerId = false;
synchronized (pageContext) {
SessionListenerId= (book.SessionListener)
pageContext.getAttribute("SessionListenerId",PageContext.PAGE_SCOPE);
if ( SessionListenerId == null ) {
_jspx_specialSessionListenerId = true;
try {
SessionListenerId = (book.SessionListener) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "book.SessionListener");
} catch (ClassNotFoundException exc) {
throw new InstantiationException(exc.getMessage());
} catch (Exception exc) {
throw new ServletException (" Cannot create bean of class "+"book.SessionListener", exc);
}
pageContext.setAttribute("SessionListenerId", SessionListenerId, PageContext.PAGE_SCOPE);
}
}
if(_jspx_specialSessionListenerId == true) {
// end
// begin [file="/browse.jsp";from=(12,0);to=(12,78)]
}
// end
// HTML // begin [file="/browse.jsp";from=(12,78);to=(13,0)]
out.write("\r\n");
// end
// begin [file="/browse.jsp";from=(13,2);to=(23,0)]
int PageSize=8;//設置每張網頁顯示8條記錄
int ShowPage=1;//設置預顯示的頁數
int RowCount=0;//ResultSet的記錄數
int PageCount=0;//ResuleSet分頁后的總頁數
ResultSet rs=bkId.executeQuery("SELECT * FROM 書籍信息表");
rs.last();//將指針移到最后一個記錄
RowCount=rs.getRow();//取得結果中的記錄數
//計算顯示的頁數
PageCount=((RowCount%PageSize)==0?(RowCount/PageSize):(RowCount/PageSize+1));
// end
// HTML // begin [file="/browse.jsp";from=(23,2);to=(40,8)]
out.write("\r\n<html>\r\n<head>\r\n<title>\r\n迷你書店\r\n</title>\r\n</head>\r\n<body bgcolor=\"#ffffff\">\r\n <center>\r\n <font size=5 color=blue>\r\n 歡迎光臨\r\n </font>\r\n </center>\r\n <center>\r\n <p>\r\n 在線人數:\r\n <font size=\"4\" color=\"red\">\r\n ");
// end
// begin [file="/browse.jsp";from=(40,11);to=(40,39)]
out.print(SessionListenerId.getCount());
// end
// HTML // begin [file="/browse.jsp";from=(40,41);to=(48,8)]
out.write("\r\n </font>\r\n </p>\r\n </center>\r\n<br >\r\n <hr >\r\n <br >\r\n <center>\r\n ");
// end
// begin [file="/browse.jsp";from=(48,10);to=(62,8)]
String ToPage=request.getParameter("ToPage");//判斷請求頁
if(ToPage!=null)//判斷是否正確取得ToPage參數
{
ShowPage=Integer.parseInt(ToPage);
if(ShowPage>PageCount)
{
ShowPage=PageCount;
}
else if(ShowPage<=0)
{
ShowPage=1;
}
}
rs.absolute(((ShowPage-1)*PageSize+1));//計算欲顯示頁的第一條記錄位置
// end
// HTML // begin [file="/browse.jsp";from=(62,10);to=(65,10)]
out.write("\r\n <h3>\r\n 當前在第<font size=4 color=red>\r\n ");
// end
// begin [file="/browse.jsp";from=(65,13);to=(65,21)]
out.print(ShowPage);
// end
// HTML // begin [file="/browse.jsp";from=(65,23);to=(67,10)]
out.write("</font>頁,共\r\n <font size=4 color=red>\r\n ");
// end
// begin [file="/browse.jsp";from=(67,13);to=(67,22)]
out.print(PageCount);
// end
// HTML // begin [file="/browse.jsp";from=(67,24);to=(78,12)]
out.write("</font>頁\r\n </h3>\r\n <br>\r\n <table border=\"1\"width=\"100%\">\r\n <tr>\r\n <td width=\"30%\">書名</td>\r\n <td width=\"30%\">作者</td>\r\n <td width=\"15%\">價格(元)</td>\r\n <td width=\"25%\">購書</td>\r\n </tr>\r\n\r\n ");
// end
// begin [file="/browse.jsp";from=(78,14);to=(82,12)]
int i=0;
while(rs.next()){
i=i+1;
// end
// HTML // begin [file="/browse.jsp";from=(82,14);to=(84,30)]
out.write("\r\n <tr>\r\n <td width=\"30%\">");
// end
// begin [file="/browse.jsp";from=(84,33);to=(84,53)]
out.print(rs.getString("name"));
// end
// HTML // begin [file="/browse.jsp";from=(84,55);to=(85,30)]
out.write("</td>\r\n <td width=\"30%\">");
// end
// begin [file="/browse.jsp";from=(85,33);to=(85,55)]
out.print(rs.getString("author"));
// end
// HTML // begin [file="/browse.jsp";from=(85,57);to=(86,30)]
out.write("</td>\r\n <td width=\"15%\">");
// end
// begin [file="/browse.jsp";from=(86,33);to=(86,51)]
out.print(rs.getInt("price"));
// end
// HTML // begin [file="/browse.jsp";from=(86,53);to=(87,56)]
out.write("</td>\r\n <td width=\"25%\"><a href=\"cart.jsp?book_id=");
// end
// begin [file="/browse.jsp";from=(87,59);to=(87,74)]
out.print(rs.getInt("id"));
// end
// HTML // begin [file="/browse.jsp";from=(87,76);to=(89,12)]
out.write("\">選購此書</a></td>\r\n </tr>\r\n ");
// end
// begin [file="/browse.jsp";from=(89,14);to=(95,12)]
//超過8條
if(i==PageSize)
{
break;
}
// end
// HTML // begin [file="/browse.jsp";from=(95,14);to=(96,12)]
out.write("\r\n ");
// end
// begin [file="/browse.jsp";from=(96,14);to=(99,12)]
}
rs.close();
// end
// HTML // begin [file="/browse.jsp";from=(99,14);to=(103,14)]
out.write("\r\n </table>\r\n <table>\r\n <tr valign=\"baseline\" align=\"center\">\r\n ");
// end
// begin [file="/browse.jsp";from=(103,16);to=(108,16)]
//判斷目前所在頁號是否為一頁,不是則顯示到第一頁與上一頁的超鏈接
if(ShowPage!=1)
{
//以顯示的分頁號ToPage為參數,超鏈接到browse.jsp
// end
// HTML // begin [file="/browse.jsp";from=(108,18);to=(110,44)]
out.write("\r\n <td width=\"150\">\r\n <a Href=browse.jsp?ToPage=");
// end
// begin [file="/browse.jsp";from=(110,47);to=(110,57)]
out.print(ShowPage-1);
// end
// HTML // begin [file="/browse.jsp";from=(110,59);to=(113,16)]
out.write(">到上一頁\r\n </a>\r\n </td>\r\n ");
// end
// begin [file="/browse.jsp";from=(113,18);to=(119,16)]
}
//判斷目前所在分頁是否為最后一頁,不是則顯示到最后一頁與下一頁的超鏈接
if(ShowPage!=PageCount)
{
//以顯示的分頁號topage為參數,超鏈接到browse.jsp
// end
// HTML // begin [file="/browse.jsp";from=(119,18);to=(121,44)]
out.write("\r\n <td width=\"150\">\r\n <a Href=browse.jsp?ToPage=");
// end
// begin [file="/browse.jsp";from=(121,47);to=(121,56)]
out.print(PageCount);
// end
// HTML // begin [file="/browse.jsp";from=(121,58);to=(124,16)]
out.write(">到最后一頁\r\n </a>\r\n </td>\r\n ");
// end
// begin [file="/browse.jsp";from=(124,18);to=(127,16)]
}
//利用表單向browse.jsp傳送要顯示的頁號
// end
// HTML // begin [file="/browse.jsp";from=(127,18);to=(133,28)]
out.write("\r\n\r\n <td width=\"150\">\r\n <form action=\"browse.jsp\" method=\"POST\" >\r\n 到\r\n <input type=\"text\"name=ToPage style=\"HEIGHT:25px;WIDTH:40px\"\r\n value=");
// end
// begin [file="/browse.jsp";from=(133,31);to=(133,39)]
out.print(ShowPage);
// end
// HTML // begin [file="/browse.jsp";from=(133,41);to=(141,0)]
out.write(">頁\r\n </form>\r\n </td>\r\n </tr>\r\n </table>\r\n </center>\r\n</body>\r\n</html>\r\n");
// end
} catch (Throwable t) {
if (out != null && out.getBufferSize() != 0)
out.clearBuffer();
if (pageContext != null) pageContext.handlePageException(t);
} finally {
if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -