()throws JspTagException { int max = 0; String ListBody = null; int number = 1; // 获取页码信息,也就是 request 对象中的内容 String serialNo = pageContext.getRequest().getParameter("serialNo"); // 转换为整数 try{ number = Integer.parseInt(serialNo); } catch(Exception e){ number = 1; } if (number < 1) number = 1; // 获取保存在 Session 中的数据集,当然这里也可以从数据库中取数据 Vector bookVector = (Vector)pageContext.getSession().getAttribute("bookVector
if(number*10<bookVector.size()) max = number*10; else max = bookVector.size(); if(bookVector.size()>0){ // 获取标签内部的内容 BodyContent bc = getBodyContent(); for (int i = (number - 1) * 10; i < max; i++) { // 获取一条记录 bookmodel model = (bookmodel) bookVector.get(i); if (model == null) model = new bookmodel(); // 替换内容(就是在这里输出数据的,替换) String body = bc.getString(); body = StringHelper.replace(body, "$_SerialNo", model.getBookid()); body = StringHelper.replace(body, "$_BookName", model.getBookname()); body = StringHelper.replace(body, "$_Author", model.getAuthor()); body = StringHelper.replace(body, "$_PHouse", model.getPhouse()); body = StringHelper.replace(body, "$_Price", model.getPrice().toString(
body = StringHelper.replace(body, "$_index", Integer.toString(i)); // 向页面输出 try{ pageContext.getOut().print(body); }
108. 109. 110. 111. 112. 113. 114. 115. 116. } } } }
catch(Exception e){
}
return EVAL_PAGE;
源码(BookList.jsp) 四,页面 JSP 源码 至此我们可以操作 JSP 来实现页面与代码分离.
117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. <h2 align="center"><font face="黑体" color="#0000CC">图书
列表</font></h2> <form name="form1" method="post"> < </head> <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0"> } </script> <script language="javascript"> function returnBack(){ document.form1.action = "BookAdmin.jsp"; <%@page contentType="text/html; charset=GBK"%> <%@ taglib uri="/MyBookTag" prefix="MyBookTag" %> <html> <head> <title>一个基于 J2EE 的图书 DEMO</ti
tle>
table width="750" border="1" cellspacing="0" align="center" cellpadding="3" borderco lor="#A5ABB6" bordercolordark="#ffffff"> 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. <tr align="center"> <td width="100" bgcolor="FEFBF4" height="41">序号</td> <td width="200" bgcolor="FEFBF4" height="41">图示名称</td> <td width="100" bgcolor="FEFBF4" height="41">图书作者</td> <td width="200" bgcolor="FEFBF4" height="41">出版社</td> <td width="50" bgcolor="FEFBF4" height="41">图书价格</td> <td width="100" bgcolor="FEFBF4" height="41">操作</td> </tr> <!--这里使用标签技术,如果不用,就麻烦了,相信您一定有感触--> <MyBookTag:ListBook>
146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168.
<tr align="center"> <td width="100" height="19">$_SerialNo</td> <td width="200" height="19">$_BookName</td> <td width="100">$_Author</td> <td width="200">$_PHouse</td> <td width="50" height="19">$_Price</td> <td width="100" height="19" align="left"> <a href="bookEditTable.jsp?ItemNo=$_index"> <font color="#0000CC">编辑</font> </a> |<a hr