📄 index_0002ejsp_jsp.java
字号:
import java.sql.*;
import book.SessionListener;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import org.apache.jasper.runtime.*;
public class index_0002ejsp_jsp extends HttpJspBase {
// begin [file="/index.jsp";from=(10,0);to=(10,56)]
// end
static {
}
public index_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=GB2312");
pageContext = _jspxFactory.getPageContext(this, request, response,
"", true, 8192, true);
application = pageContext.getServletContext();
config = pageContext.getServletConfig();
session = pageContext.getSession();
out = pageContext.getOut();
// HTML // begin [file="/index.jsp";from=(0,51);to=(1,0)]
out.write("\r\n");
// end
// HTML // begin [file="/index.jsp";from=(1,31);to=(2,2)]
out.write("\r\n//");
// end
// HTML // begin [file="/index.jsp";from=(2,43);to=(3,0)]
out.write("\r\n");
// end
// HTML // begin [file="/index.jsp";from=(3,27);to=(4,0)]
out.write("\r\n");
// end
// begin [file="/index.jsp";from=(4,2);to=(9,0)]
if(session.getAttribute("username")==null)
{
response.sendRedirect("login.html");
}
// end
// HTML // begin [file="/index.jsp";from=(9,2);to=(10,0)]
out.write("\r\n");
// end
// begin [file="/index.jsp";from=(10,0);to=(10,56)]
book.bk mybook = null;
boolean _jspx_specialmybook = false;
synchronized (pageContext) {
mybook= (book.bk)
pageContext.getAttribute("mybook",PageContext.PAGE_SCOPE);
if ( mybook == null ) {
_jspx_specialmybook = true;
try {
mybook = (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("mybook", mybook, PageContext.PAGE_SCOPE);
}
}
if(_jspx_specialmybook == true) {
// end
// begin [file="/index.jsp";from=(10,0);to=(10,56)]
}
// end
// HTML // begin [file="/index.jsp";from=(10,56);to=(11,0)]
out.write("\r\n");
// end
// begin [file="/index.jsp";from=(11,2);to=(22,0)]
int PageSize = 8; //设置每张网页显示五笔记录
int ShowPage = 1; //设置欲显示的页数
int RowCount = 0; //ResultSet的记录笔数
int PageCount = 0; //ResultSet分页后的总页数
ResultSet rs = mybook.executeQuery("SELECT * FROM 书籍信息"); //建立ResultSet(结果集)对象,并执行SQL语句
rs.last(); //将指标移至最后一笔记录
RowCount = rs.getRow(); //取得ResultSet中记录的笔数
//计算显示的页数
PageCount = ((RowCount % PageSize) == 0 ?
(RowCount/PageSize) : (RowCount/PageSize)+1);
// end
// HTML // begin [file="/index.jsp";from=(22,2);to=(31,16)]
out.write("\r\n<HTML>\r\n<HEAD>\r\n<TITLE>迷你书店</TITLE>\r\n</HEAD>\r\n<BODY>\r\n<CENTER>\r\n<FONT SIZE = 5 COLOR = blue>欢迎光临我的书店</FONT>\r\n</CENTER>\r\n<center><P>在线人数:");
// end
// begin [file="/index.jsp";from=(31,19);to=(31,47)]
out.print( SessionListener.getCount() );
// end
// HTML // begin [file="/index.jsp";from=(31,49);to=(36,0)]
out.write("</P></center>\r\n<BR>\r\n<HR>\r\n<BR>\r\n<CENTER>\r\n");
// end
// begin [file="/index.jsp";from=(36,2);to=(51,0)]
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); //计算欲显示页的第一笔记录位置
// end
// HTML // begin [file="/index.jsp";from=(51,2);to=(53,0)]
out.write("\r\n<H3>当前在第<FONT SIZE = 4 COLOR = red>\r\n");
// end
// begin [file="/index.jsp";from=(53,3);to=(53,13)]
out.print( ShowPage );
// end
// HTML // begin [file="/index.jsp";from=(53,15);to=(55,0)]
out.write("</FONT>页, 共\r\n<FONT SIZE = 4 COLOR = red>\r\n");
// end
// begin [file="/index.jsp";from=(55,3);to=(55,14)]
out.print( PageCount );
// end
// HTML // begin [file="/index.jsp";from=(55,16);to=(65,0)]
out.write("</FONT>页</H3>\r\n<BR>\r\n\r\n<table border=\"1\" width=\"100%\">\r\n <tr>\r\n <td width=\"33%\">书名</td>\r\n <td width=\"33%\">作者</td>\r\n <td width=\"10%\">价格(元)</td>\r\n <td width=\"24%\">购书</td>\r\n </tr>\r\n");
// end
// begin [file="/index.jsp";from=(65,2);to=(68,0)]
int i = 0;
while (rs.next()) {
i = i + 1;
// end
// HTML // begin [file="/index.jsp";from=(68,2);to=(70,20)]
out.write("\r\n<tr>\r\n <td width=\"35%\">");
// end
// begin [file="/index.jsp";from=(70,23);to=(70,43)]
out.print(rs.getString("name"));
// end
// HTML // begin [file="/index.jsp";from=(70,45);to=(71,20)]
out.write("</td>\r\n <td width=\"33%\">");
// end
// begin [file="/index.jsp";from=(71,23);to=(71,45)]
out.print(rs.getString("author"));
// end
// HTML // begin [file="/index.jsp";from=(71,47);to=(72,20)]
out.write("</td>\r\n <td width=\"10%\">");
// end
// begin [file="/index.jsp";from=(72,23);to=(72,43)]
out.print((rs.getInt("price")));
// end
// HTML // begin [file="/index.jsp";from=(72,45);to=(73,46)]
out.write("</td>\r\n <td width=\"22%\"><a href=\"cart.jsp?book_id=");
// end
// begin [file="/index.jsp";from=(73,49);to=(73,64)]
out.print(rs.getInt("id"));
// end
// HTML // begin [file="/index.jsp";from=(73,66);to=(75,0)]
out.write("\">选购此书</a></td>\r\n </tr>\r\n");
// end
// begin [file="/index.jsp";from=(75,2);to=(81,0)]
//超过8条
if(i ==PageSize)
{
break;
}
// end
// HTML // begin [file="/index.jsp";from=(81,2);to=(82,0)]
out.write("\r\n");
// end
// begin [file="/index.jsp";from=(82,2);to=(85,0)]
}
rs.close();
// end
// HTML // begin [file="/index.jsp";from=(85,2);to=(89,0)]
out.write("\r\n</table>\r\n<TABLE>\r\n<TR valign=baseline align=center>\r\n");
// end
// begin [file="/index.jsp";from=(89,2);to=(96,2)]
//判断目前所在分页是否为第一页,
//不是则显示到第一页与上一页的超链接
if(ShowPage != 1)
{
//下面建立的各超链接将链接至自己,
//并将欲显示的分页以ToPage参数传递给自己
// end
// HTML // begin [file="/index.jsp";from=(96,4);to=(98,27)]
out.write("\r\n <TD Width=150>\r\n <A Href=index.jsp?ToPage=");
// end
// begin [file="/index.jsp";from=(98,30);to=(98,33)]
out.print( 1 );
// end
// HTML // begin [file="/index.jsp";from=(98,35);to=(101,27)]
out.write(">到第一页</A>\r\n </TD>\r\n <TD Width=150>\r\n <A Href=index.jsp?ToPage=");
// end
// begin [file="/index.jsp";from=(101,30);to=(101,44)]
out.print( ShowPage - 1 );
// end
// HTML // begin [file="/index.jsp";from=(101,46);to=(103,2)]
out.write(">到上一页</A>\r\n </TD>\r\n ");
// end
// begin [file="/index.jsp";from=(103,4);to=(111,2)]
}
//判断目前所在分页是否为最后一页,
//不是则显示到最后一页与下一页的超链接
if(ShowPage != PageCount)
{
//下面建立的各超链接将链接至自己,
//并将欲显示的分页以ToPage参数传递自己
// end
// HTML // begin [file="/index.jsp";from=(111,4);to=(113,27)]
out.write("\r\n <TD Width=150>\r\n <A Href=index.jsp?ToPage=");
// end
// begin [file="/index.jsp";from=(113,30);to=(113,43)]
out.print( ShowPage + 1);
// end
// HTML // begin [file="/index.jsp";from=(113,45);to=(116,27)]
out.write(">到下一页</A>\r\n </TD>\r\n <TD Width=150>\r\n <A Href=index.jsp?ToPage=");
// end
// begin [file="/index.jsp";from=(116,30);to=(116,41)]
out.print( PageCount );
// end
// HTML // begin [file="/index.jsp";from=(116,43);to=(118,2)]
out.write(">到最后一页</A>\r\n </TD>\r\n ");
// end
// begin [file="/index.jsp";from=(118,4);to=(120,0)]
}
// end
// HTML // begin [file="/index.jsp";from=(120,2);to=(125,7)]
out.write("\r\n<TD Width=150>\r\n<FORM action=index.jsp method=POST>\r\n到\r\n<INPUT type=\"text\" name=ToPage style=\"HEIGHT: 25px; WIDTH: 40px\"\r\n value=");
// end
// begin [file="/index.jsp";from=(125,10);to=(125,19)]
out.print( ShowPage);
// end
// HTML // begin [file="/index.jsp";from=(125,21);to=(130,7)]
out.write(" > 页\r\n</FORM></TD></TR>\r\n</TABLE>\r\n</CENTER>\r\n</BODY>\r\n</HTML>");
// 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 + -