📄 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 + -