`
thinktothings
  • 浏览: 782171 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

display table外部分页,支持外部排序

    博客分类:
  • JSP
阅读更多

display table外部分页,支持外部排序

 

操作步骤:

第一部:

web.xml

<!--引入标签-->

 

<jsp-config>
  <taglib>

   <taglib-uri>http://jsptags.com/tags/navigation/pager</taglib-uri>

   <taglib-location>/WEB-INF/displaytag-11.tld</taglib-location>

   </taglib>

 </jsp-config>

 

<!--配置,分页后台业务处理servlet-->

<servlet-mapping>
  <servlet-name>CustomerServlet</servlet-name>
  <url-pattern>/servlet/CustomerServlet</url-pattern>
 </servlet-mapping>

<!--欢迎页面-->
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>

 

 

 

欢迎页面 index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">

  </head>
  
  <body>
    <h1><a href="<%=request.getContextPath()%>/servlet/CustomerServlet"><%=request.getContextPath()%>/servlet/CustomerServlet</a></h1>
  </body>
</html>

 

 

result.jsp

 

result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib  prefix="display" uri="http://displaytag.sf.net" %> 
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

			<link rel="stylesheet" href="<%=request.getContextPath()%>/css/print.css" type="text/css" media="print" />
		<link rel="stylesheet" href="<%=request.getContextPath()%>/css/screen.css" type="text/css" media="screen,print" />  
  </head>
  
  <body>

    	<display:table name="list" 
				class="its" id="item" name="list" sort="external"  pagesize="${pageSize}" partialList="true" size="resultSize"  requestURI="/displaypagination/servlet/CustomerServlet">  
			  
			    <display:column property="id"  title="I"  ></display:column>
				<display:column property="numcuguid"  title="ID" sortable="true" ></display:column>
                <display:column property="vc2cuname"  title="vc2cuname" sortable="true"></display:column>
				<display:column property="vc2cucode" title="vc2cucode"  sortable="true"></display:column>
			</display:table>	
    
  </body>
</html>

 

 

 

servlet

com.tht.customer.servlet.CustomerServlet.java

 

package com.tht.customer.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.displaytag.pagination.Pagination;
import org.displaytag.tags.TableTagParameters;
import org.displaytag.util.ParamEncoder;

import com.tht.common.db.base.BaseDao;
import com.tht.common.oracle.paging.PageTools;
import com.tht.customer.dao.CustomerDao;
import com.tht.customer.vo.CustomerVO;

public class CustomerServlet extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public CustomerServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		//int resultSize=100;//总页数
		int pageSize=5;//每页显示的记录数
		
		//得到当前页的字符串
		String strP=request.getParameter((new ParamEncoder("item").encodeParameterName(TableTagParameters.PARAMETER_PAGE)));
	
		//请求的需要显示的页码数
		int currentPage=0;
	    if(strP==null){
	    	currentPage=1;
	    }else{
	    	currentPage=Integer.parseInt(strP);
	    }
		//当前页
		System.out.println("currentPage:"+currentPage);
		
		
		//排序功能
		int sortIndex=-1;//排序索引列,第一列为0
		int orderIndex=-1;//1为升序,2为降序

		
		String strSort= request.getParameter((new ParamEncoder("item").encodeParameterName(TableTagParameters.PARAMETER_SORT)));
		if(strSort==null){
			 sortIndex=-1;
		}else{
			sortIndex=Integer.parseInt(strSort);
		}
		System.out.println("sortIndex:"+sortIndex);
		
		String strOrder= request.getParameter((new ParamEncoder("item").encodeParameterName(TableTagParameters.PARAMETER_ORDER)));
		
		if(strOrder==null){
			orderIndex=-1;
		}else{
			orderIndex=Integer.parseInt(strOrder);
		}
		System.out.println("orderIndex:"+orderIndex);
		
		
		
		//总记录数
        int totalCount=new BaseDao<CustomerServlet>().getTotalCount("select count(*) from ct_cuinfo");
	
        PageTools pagination=new PageTools(currentPage,pageSize,totalCount);
		
        pagination.setSortIndex(sortIndex);
        pagination.setOrderIndex(orderIndex);

      
	
		
		
		CustomerDao customerDao=new CustomerDao();
		List<CustomerVO> list=customerDao.getList(pagination);
		System.out.println("==============servlet============");
		for(CustomerVO vo:list){
			System.out.println(vo.getId());
		}
		request.setAttribute("list", list);

		
		request.setAttribute( "pageSize" , pageSize); // 每页显示的条数
		request.setAttribute( "resultSize" , totalCount); // 将总记录数保存成Intger实例保存在request中
		request.getRequestDispatcher("/result.jsp").forward(request, response); 
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		out
				.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
		out.println("<HTML>");
		out.println("  <HEAD><TITLE>A Servlet</TITLE></HEAD>");
		out.println("  <BODY>");
		out.print("    This is ");
		out.print(this.getClass());
		out.println(", using the POST method");
		out.println("  </BODY>");
		out.println("</HTML>");
		out.flush();
		out.close();
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}

 

 

  • 大小: 17.1 KB
分享到:
评论

相关推荐

    display table 外部分页 不支持排序

    在IT行业中,"display table 外部分页 不支持排序"是一个常见的前端开发问题,尤其是在处理大量数据时。Display table通常指的是HTML中的`&lt;table&gt;`元素,用于展示表格数据。外部分页则是指将数据分块加载,而不是一...

    display table 外部分页 支持当前页排序

    "display table 外部分页 支持当前页排序"这个主题聚焦于如何在网页上有效地显示大量表格数据,同时提供分页功能和当前页面的排序能力。这种技术常用于Web应用程序,如后台管理系统、数据分析平台等,旨在提升用户...

    FlexiGrid使用手册

    &lt;table id="flexTable" style="display: none"&gt;&lt;/table&gt; ``` c. 编写JavaScript代码初始化FlexiGrid: ```javascript $(document).ready(function(){ var grid=$("#flexTable").flexigrid({ width: 760, ...

    java ee 表格的绘制

    通过设置`border`、`padding`、`color`、`font-family`等属性调整表格的外观,使用`width`、`height`控制尺寸,`display: table-cell`确保元素按表格布局排列。 4. JavaScript与jQuery JavaScript和jQuery可以用来...

    基于jquery实现的表格分页实现代码

    6. 代码结构与模块化:在给出的内容中可以看到,表格的HTML结构使用了`&lt;table&gt;`元素,并且每一列的表头都附加了排序功能(通过鼠标悬停时显示的上下箭头)。这表示实现分页功能的同时,还可以提供列排序的功能。同时...

    表格樣式

    可能还会涉及到现代前端框架(如Bootstrap)中预设的表格样式,或者使用JavaScript和jQuery实现交互效果,如排序、筛选和分页。 标签中的“工具”可能暗示着一些辅助工具或库,比如CSS预处理器(如Sass、Less)能...

    常用jar包

    4. **使用标签**:在JSP页面中,使用Displaytag的标签如`&lt;display:table&gt;`、`&lt;display:column&gt;`等来定义表格和列。 5. **配置属性**:通过设置标签的属性,如`export`, `sort`, `paging`等,来开启或调整Displaytag...

    前端笔试题-2020年2月27日.docx

    2. **link 和 @import 区别**:`link`是HTML标签,用于引入外部CSS文件,可实现异步加载,支持浏览器缓存,同时可以实现DNS预解析,加载性能更好;`@import`是CSS语法,只能在CSS文件内部使用,会阻塞页面渲染直到...

    cms后台管理

    &lt;class name="MyContent" table="jc_mycontent"&gt; &lt;meta attribute="sync-DAO"&gt;false&lt;/meta&gt; &lt;cache usage="read-write"/&gt; &lt;id name="id" type="java.lang.Integer" column="id"&gt;&lt;generator class=...

Global site tag (gtag.js) - Google Analytics