import java.io.*; import java.util.*; import com.sun.im […]
jsp分页类
jsp分页类 package data; import java.sql.*; /* *类名 Paginati […]
JSP页面显示乱码问题的解决
大家在JSP的开发过程中,经常出现中文乱码的问题,可能一至困扰着您,我现在把我在JSP开发中遇到的中文乱码的问 […]
如何在Struts中实现分页显示数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 |
如何在Struts中实现分页显示数据 PageData类代码: 1import java.util.Collection; 2 3/**//** 4 * <p>Title: </p> 5 * <p>Description: </p> 6 * <p>Copyright: Copyright (c) 2003</p> 7 * <p>Company: </p> 8 * @author George Hill 9 * @version 1.0 10 */ 11 12public class PageData { 13 14 /**//** 15 * 每页显示的数据行数 16 */ 17 public final static int NUMBER_PER_PAGE = 15; 18 19 /**//** 20 * 保存页面显示的数据集合 21 */ 22 protected Collection list; 23 24 /**//** 25 * 当前页数 26 */ 27 protected int page; 28 29 /**//** 30 * 最大页数 31 */ 32 protected int maxPage; 33 34 /**//** 35 * 无参构造方法 36 */ 37 public PageData() {} 38 39 /**//** 40 * 构造方法 41 * @param list 数据集 42 * @param page 当前页数 43 * @param maxPage 最大页数 44 */ 45 public PageData(Collection list, int page, int maxPage) { 46 this.list = list; 47 this.page = page; 48 this.maxPage = maxPage; 49 } 50 51 /**//** 52 * 获得数据集合 53 * @return 数据集合 54 */ 55 public Collection getList() { 56 return this.list; 57 } 58 59 /**//** 60 * 设置数据集合 61 * @param list 新的数据集合 62 */ 63 public void setList(Collection list) { 64 this.list = list; 65 } 66 67 /**//** 68 * 获得当前页数 69 * @return 当前页数 70 */ 71 public int getPage() { 72 return this.page; 73 } 74 75 /**//** 76 * 获得上页页数 77 * @return 上页页数 78 */ 79 public int getPrePage() { 80 int prePage = page - 1; 81 82 if (prePage <= 0) 83 prePage = 1; 84 85 return prePage; 86 } 87 88 /**//** 89 * 获得下页页数 90 * @return 下页页数 91 */ 92 public int getNextPage() { 93 int next = page + 1; 94 95 if (next > maxPage) 96 next = maxPage; 97 98 return next; 99 } 100 101 /**//** 102 * 设置当前页数 103 * @param page 当前页数新值 104 */ 105 public void setPage(int page) { 106 this.page = page; 107 } 108 109 /**//** 110 * 获得最大页数 111 * @return 最大页数 112 */ 113 public int getMaxPage() { 114 return this.maxPage; 115 } 116 117 /**//** 118 * 设置最大页数 119 * @param maxPage 最大页数新值 120 */ 121 public void setMaxPage(int maxPage) { 122 this.maxPage = maxPage; 123 } 124 125 /**//** 126 * 获得首页标识 127 * @return 首页标识 128 */ 129 public boolean isFirstPage() { 130 if (this.page <= 1) 131 return true; 132 133 return false; 134 } 135 136 /**//** 137 * 获得末页标识 138 * @return 末页标识 139 */ 140 public boolean isLastPage() { 141 if (this.page >= this.maxPage) 142 return true; 143 144 return false; 145 } 146} 147 TurnPageForm类代码: 1import javax.servlet.http.*; 2import org.apache.struts.action.*; 3 4/**//** 5 * <p>Title: </p> 6 * <p>Description: </p> 7 * <p>Copyright: Copyright (c) 2003</p> 8 * <p>Company: </p> 9 * @author George Hill 10 * @version 1.0 11 */ 12 13public class TurnPageForm extends ActionForm{ 14 15 /**//** 16 * 要跳转的页码 17 */ 18 protected int page; 19 20 /**//** 21 * 跳转按钮 22 */ 23 protected String turn; 24 25 /**//** 26 * 首页按钮 27 */ 28 protected String first; 29 30 /**//** 31 * 上一页按钮 32 */ 33 protected String preview; 34 35 /**//** 36 * 下一页按钮 37 */ 38 protected String next; 39 40 /**//** 41 * 末页按钮 42 */ 43 protected String last; 44 45 /**//** 46 * 跳转地址 47 */ 48 protected String url; 49 50 /**//** 51 * 当前页码 52 */ 53 protected int currentPage; 54 55 /**//** 56 * 最大页码 57 */ 58 protected int maxPage; 59 60 /**//** 61 * 获得跳转页码 62 * @return 跳转页码 63 */ 64 public int getPage() { 65 return this.page; 66 } 67 68 /**//** 69 * 设置跳转页码 70 * @param page 跳转页码值 71 */ 72 public void setPage(int page) { 73 this.page = page; 74 } 75 76 /**//** 77 * 获得跳转按钮值 78 * @return 跳转按钮值 79 */ 80 public String getTurn() { 81 return this.turn; 82 } 83 84 /**//** 85 * 设置跳转按钮值 86 * @param turn 跳转按钮值 87 */ 88 public void setTurn(String turn) { 89 this.turn = turn; 90 } 91 92 /**//** 93 * 获得首页按钮值 94 * @return 首页按钮值 95 */ 96 public String getFirst() { 97 return this.first; 98 } 99 100 /**//** 101 * 设置首页按钮值 102 * @param first 首页按钮值 103 */ 104 public void setFirst(String first) { 105 this.first = first; 106 } 107 108 /**//** 109 * 获得上一页按钮值 110 * @return 上一页按钮值 111 */ 112 public String getPreview() { 113 return this.preview; 114 } 115 116 /**//** 117 * 设置上一页按钮值 118 * @param preview 上一页按钮值 119 */ 120 public void setPreview(String preview) { 121 this.preview = preview; 122 } 123 124 /**//** 125 * 获得下一页按钮值 126 * @return 下一页按钮值 127 */ 128 public String getNext() { 129 return this.next; 130 } 131 132 /**//** 133 * 设置下一页按钮值 134 * @param next 下一页按钮值 135 */ 136 public void setNext(String next) { 137 this.next = next; 138 } 139 140 /**//** 141 * 获得末页按钮值 142 * @return 末页按钮值 143 */ 144 public String getLast() { 145 return this.last; 146 } 147 148 /**//** 149 * 设置末页按钮值 150 * @param last 末页按钮值 151 */ 152 public void setLast(String last) { 153 this.last = last; 154 } 155 156 /**//** 157 * 获得跳转地址 158 * @return 跳转地址 159 */ 160 public String getUrl() { 161 return this.url; 162 } 163 164 /**//** 165 * 设置跳转地址 166 * @param url 跳转地址 167 */ 168 public void setUrl(String url) { 169 this.url = url; 170 } 171 172 /**//** 173 * 获得当前页码 174 * @return 当前页码 175 */ 176 public int getCurrentPage() { 177 return this.currentPage; 178 } 179 180 /**//** 181 * 设置当前页码 182 * @param page 当前页码值 183 */ 184 public void setCurrentPage(int page) { 185 this.currentPage = page; 186 } 187 188 /**//** 189 * 获得最大页码 190 * @return 最大页码 191 */ 192 public int getMaxPage() { 193 return this.maxPage; 194 } 195 196 /**//** 197 * 设置最大页码 198 * @param page 最大页码 199 */ 200 public void setMaxPage(int page) { 201 this.maxPage = page; 202 } 203 204 /**//** 205 * 重置属性 206 * @param mapping action映射 207 * @param request HTTP请求 208 */ 209 public void reset(ActionMapping mapping, HttpServletRequest request) { 210 this.page = 0; 211 this.turn = null; 212 this.first = null; 213 this.preview = null; 214 this.next = null; 215 this.last = null; 216 this.url = null; 217 this.currentPage = 0; 218 this.maxPage = 0; 219 } 220 221} 222 TurnPageAction代码: 1import java.io.*; 2import javax.servlet.*; 3import javax.servlet.http.*; 4 5import org.apache.struts.action.*; 6 7import xxx.TurnPageForm; 8 9/**//** 10 * <p>Title: </p> 11 * <p>Description: </p> 12 * <p>Copyright: Copyright (c) 2003</p> 13 * <p>Company: </p> 14 * @author George Hill 15 * @version 1.0 16 */ 17 18public class TurnPageAction extends Action { 19 20 /**//** 21 * 执行用户的跳转页面请求 22 * @param mapping 转发映射表 23 * @param form 请求的ActionForm Bean 24 * @param request 用户请求 25 * @param response 用户应答 26 * @return 成功或者失败的转发 27 * @throws IOException IO例外 28 * @throws ServletException Servlet例外 29 */ 30 public ActionForward execute(ActionMapping mapping, ActionForm form, 31 HttpServletRequest request, 32 HttpServletResponse response) throws IOException, 33 ServletException { 34 if (form instanceof TurnPageForm) { 35 TurnPageForm tform = (TurnPageForm) form; 36 int page = 0; 37 String url = null; 38 39 if (tform.getTurn() != null) { 40 page = tform.getPage(); 41 } else if (tform.getFirst() != null) { 42 page = 1; 43 } else if (tform.getPreview() != null) { 44 page = tform.getCurrentPage() - 1; 45 } else if (tform.getNext() != null) { 46 page = tform.getCurrentPage() + 1; 47 } else if (tform.getLast() != null) { 48 page = tform.getMaxPage(); 49 } 50 51 if (page < 1) { 52 page = 1; 53 } else if (page > tform.getMaxPage()) { 54 page = tform.getMaxPage(); 55 } 56 if (tform.getUrl().indexOf("?") == -1) { 57 url = tform.getUrl() + "?page=" + page; 58 } else { 59 url = tform.getUrl() + "&page=" + page; 60 } 61 return new ActionForward(url); 62 } 63 64 return mapping.findForward("error"); 65 } 66} 67 struts-config.xml的相关片断: 1<?xml version="1.0" encoding="UTF-8"?> 2<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"> 3<struts-config> 4 <form-beans> 5 6 <form-bean name="turnPageForm" type="xxx.TurnPageForm" /> 7 8 </form-bean> 9 <action-mappings> 10 11 <action name="turnPageForm" path="/turnPage" scope="request" type="xxx.TurnPageAction" /> 12 </action-mappings> 13</struts-config> action类 1import java.util.List; 2import javax.servlet.http.*; 3 4import org.apache.struts.action.*; 5 6import xxx.Administrator; 7import xxx.TurnPageForm; 8import xxx.PageData; 9 10/**//** 11 * <p>Title: </p> 12 * 13 * <p>Description: </p> 14 * 15 * <p>Copyright: Copyright (c) 2003</p> 16 * 17 * <p>Company: </p> 18 * 19 * @author George Hill 20 * @version 1.0 21 */ 22 23public class AdminListAction extends Action { 24 25 private static final int NUMBER = 15; 26 27 /**//** 28 * 执行管理员列表操作 29 * @param mapping ActionMapping 30 * @param form ActionForm 31 * @param request HttpServletRequest 32 * @param response HttpServletResponse 33 * @throws Exception 34 * @return ActionForward 35 */ 36 public ActionForward execute(ActionMapping mapping, ActionForm form, 37 HttpServletRequest request, 38 HttpServletResponse response) throws Exception { 39 HttpSession session = request.getSession(); 40 41 //获取页码 42 String pageStr = request.getParameter("page"); 43 if (pageStr == null) 44 pageStr = String.valueOf(session.getAttribute("page")); 45 else 46 session.setAttribute("page", pageStr); 47 int page = 1; 48 try { 49 page = Integer.parseInt(pageStr); 50 } catch (NumberFormatException nfe) { 51 } 52 53 //获得总记录数 54 int count = Administrator.countAllAdministrators(); 55 int maxPage = count / NUMBER; 56 if (count % NUMBER != 0) 57 maxPage++; 58 59 //获得列表 60 List list = Administrator.getAdministrators(NUMBER, (page - 1) * NUMBER); 61 62 if (count != 0 && list == null) 63 list = Administrator.getAdministrators(NUMBER, 0); 64 65 if (list != null) { 66 PageData data = new PageData(list, page, maxPage); 67 68 request.setAttribute("admins", data); 69 } 70 71 //分页部分 72 TurnPageForm tform = new TurnPageForm(); 73 tform.setCurrentPage(page); 74 tform.setMaxPage(maxPage); 75 request.setAttribute("turnPageForm", tform); 76 77 return mapping.findForward("list"); 78 } 79} 80 jsp显示 1 <logic:present name="admins"> 2 <table width="90%" border="0" align="center" cellpadding="0" cellspacing="1" class="table6"> 3 <tr align="center" class="table4"> 4 <td width="10%" height="18" align="center" nowrap class="head1"><bean:message key="list.index"/></td> 5 <td width="20%" class="head1" align="center" nowrap><bean:message key="admin.account"/></td> 6 <td width="30%" class="head1" align="center" nowrap><bean:message key="admin.name"/></td> 7 <td width="10%" class="head1" align="center" nowrap><bean:message key="admin.status"/></td> 8 <td width="30%" class="head1" align="center" nowrap><bean:message key="list.action"/></td> 9 </tr> 10 <logic:iterate name="admins" property="list" id="entry" indexId="index"> 11 <tr class="table5" onmouseover="changeColor(this, '#99CCFF')" onmouseout="changeColor(this, '#F2F3F4')"> 12 <td align="center" nowrap><bean:write name="index"/></td> 13 <td align="center" nowrap><bean:write name="entry" property="account"/></td> 14 <td align="center" nowrap><bean:write name="entry" property="name"/></td> 15 <logic:equal name="entry" property="status" value="true"> 16 <td align="center" nowrap><bean:message key="status.enable"/></td> 17 <td align="center" nowrap> 18 <html:link page="/disableAdmin.do?status=false" paramId="account" paramName="entry" paramProperty="account" onclick="return MM_popupDisableMsg()"> 19 <font color="red"><bean:message key="status.disable"/></font> 20 </html:link> 21 <html:link page="/modifyAdmin.do?action=link" paramId="account" paramName="entry" paramProperty="account"> 22 <bean:message key="action.modify"/> 23 </html:link> 24 <html:link action="/deleteAdmin" paramId="account" paramName="entry" paramProperty="account" onclick="return MM_popupDelMsg()"> 25 <font color="red"><bean:message key="action.delete"/></font> 26 </html:link> 27 </td> 28 </logic:equal> 29 <logic:equal name="entry" property="status" value="false"> 30 <td align="center" nowrap><font color="red"><bean:message key="status.disable"/></font></td> 31 <td align="center" nowrap> 32 <html:link page="/enableAdmin.do?status=true" paramId="account" paramName="entry" paramProperty="account"> 33 <bean:message key="status.enable"/> 34 </html:link> 35 <html:link page="/modifyAdmin.do?action=link" paramId="account" paramName="entry" paramProperty="account"> 36 <bean:message key="action.modify"/> 37 </html:link> 38 <html:link action="/deleteAdmin" paramId="account" paramName="entry" paramProperty="account" onclick="return MM_popupDelMsg()"> 39 <font color="red"><bean:message key="action.delete"/></font> 40 </html:link> 41 </td> 42 </logic:equal> 43 </tr> 44 </logic:iterate> 45 </table> 46 <table width="90%" border="0" align="center" cellpadding="3" cellspacing="0"> 47 <tr> 48 <td align="left"></td> 49 <html:form action="/turnPage" method="POST"> 50 <td align="right" nowrap> 51 <html:hidden property="url" value="/listAdmin.do"/> 52 <html:hidden property="currentPage"/> 53 <html:hidden property="maxPage"/> 54 <bean:message key="page.the"/> 55 <bean:write name="admins" property="page"/> 56 <bean:message key="page.page"/>/ 57 <bean:message key="page.all"/><bean:write name="admins" property="maxPage"/><bean:message key="page.page"/> 58 <bean:message key="page.turn"/> 59 <logic:equal name="admins" property="maxPage" value="1"> 60 <html:text property="page" styleClass="input_log" styleId="page" size="3" value="" disabled="true"/> 61 <html:submit property="turn" styleClass="t_input" styleId="turn" value="GO" disabled="true"/> 62 </logic:equal> 63 <logic:notEqual name="admins" property="maxPage" value="1"> 64 <html:text property="page" styleClass="input_log" styleId="page" size="3" value=""/> 65 <html:submit property="turn" styleClass="t_input" styleId="turn" value="GO"/> 66 </logic:notEqual> 67 <logic:equal name="admins" property="firstPage" value="true"> 68 <html:submit property="first" styleClass="t_input" styleId="first" disabled="true"><bean:message key="page.first"/></html:submit> 69 <html:submit property="preview" styleClass="t_input" styleId="preview" disabled="true"><bean:message key="page.previous"/></html:submit> 70 </logic:equal> 71 <logic:notEqual name="admins" property="firstPage" value="true"> 72 <html:submit property="first" styleClass="t_input" styleId="first"><bean:message key="page.first"/></html:submit> 73 <html:submit property="preview" styleClass="t_input" styleId="preview"><bean:message key="page.previous"/></html:submit> 74 </logic:notEqual> 75 <logic:equal name="admins" property="lastPage" value="true"> 76 <html:submit property="next" styleClass="t_input" styleId="next" disabled="true"><bean:message key="page.next"/></html:submit> 77 <html:submit property="last" styleClass="t_input" styleId="last" disabled="true"><bean:message key="page.last"/></html:submit> 78 </logic:equal> 79 <logic:notEqual name="admins" property="lastPage" value="true"> 80 <html:submit property="next" styleClass="t_input" styleId="next"><bean:message key="page.next"/></html:submit> 81 <html:submit property="last" styleClass="t_input" styleId="last"><bean:message key="page.last"/></html:submit> 82 </logic:notEqual> 83 </td> 84 </html:form> 85 </tr> 86 </table> 87 </logic:present> |
Download.jsp
课程主题 之前,写过一个Download.jsp文件,可以解决下载文件乱码问题(诸如:DOC,XSL文件等等) […]
jspsmart的使用
jspsmart的使用 上传 // 新建一个SmartUpload对象 SmartUpload su = ne […]
LobPros
//Source file: C:\\Rose2Java\\zhsoft\\test\\LobPros.jav […]
Jdbc连Sybase数据库的几种方法
1.单用一个JSP文件测试SYBASE jconnect-5_2 JDBC数据库接口: <%@ page […]
JSP连接各种数据库代码
连接MS SQL SERVER 2000 <%@ page contentType=”tex […]
使用 System.Web.Mail发送邮件
//simple email MailMessage mail = new MailMessage(); ma […]
ASP.NET程序中常用代码汇总
1. 打开新的窗口并传送参数: //传送参数: response.write(“<script>w […]
ASP.net中与数据库连接全
strConnection+=Server.MapPath(“*.mdb”); //* […]
ASP.NET数据库连接实例
using System; using System.Collections; using System.Co […]
关于ASP.NET读取XML新闻的问题
单位需要更新一下以前的新闻系统,需要与现代社会接轨,因此开始研究了一下XML来存储新闻的方法。 找到了网上流传 […]
asp到.net遗留的二十大积习
在技术更新的进程中, 仍然有一些人死抱着已经过了气的东西不放. 也有一些人虽然进入到新的世界, 但仍摆脱不了陈 […]
学习asp.net总结
学习asp.net总结(之一)[转] 认识Microsoft公司的Asp.net有一段时间了,感觉asp.ne […]
asp个人整理
1.函數array() 功能:創建一個數組變量 格式:array(list) 參數:list 為數組變量中的每 […]
条形码生成.asp
<html> <head> <meta http-equiv=”Co […]
CONTPAGE.ASP
<% Set Conn=Server.CreateObject(“ADODB.Connect […]
如何使用Jmail发送邮件
<% Set msg = Server.CreateObject(“JMail.Messag […]
关于较长文章手动分页的实现方法
‘************************************* ‘Cod […]
常用函数
计数器 数据结构 [counter] count 数字 sdate 日期 ldate 日期 today all […]
sitemap生成
<% Server.ScriptTimeout=50000 ‘ sitemap_gen.as […]
flash变换
<% dim xpic,xswf randomize xpic=”swf/xpic/R […]
ASP自动解压RAR文件
其实想实现这种功能很简单,首先要上传一个RAR的解压程序,就是RAR自己的解压程序,只需要它的核心 程序R […]