1、准备tld文件

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
<description><![CDATA["To make it easier to access dynamic data;
the Apache Struts framework includes a library of custom tags.
The tags interact with the framework's validation and internationalization features;
to ensure that input is correct and output is localized.
The Struts Tags can be used with JSP FreeMarker or Velocity."]]></description>
<display-name>LetGo</display-name>
<tlib-version>1.0</tlib-version>
<short-name>voice</short-name>
<uri>/page-tags</uri>
<tag>
<description><![CDATA[Render a paging link tag]]></description>
<name>paging</name>
<tag-class>com.page.PagingAction</tag-class>
<body-content>empty</body-content>
<attribute>
<description><![CDATA[current page index]]></description>
<name>currPage</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description><![CDATA[The total page]]></description>
<name>totalPage</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description><![CDATA[The page max]]></description>
<name>pageMax</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<description><![CDATA[total link number for show]]></description>
<name>count</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
</tag>
</taglib>

2、写相应的处理类 继承的是 jsp-api.jar 中 SimpleTagSupport,在该类中同时也可以设置各个按钮的js事件....

 package com.page;

 import java.io.IOException;

 import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport; import com.opensymphony.xwork2.ActionContext; public class PagingAction extends SimpleTagSupport{ private String currPage;
private String totalPage;
private String pageMax;
private String count; /**
* 返回
* @return
*/
public String getCurrPage() {
return currPage;
} /**
* 设置
* @param
*/
public void setCurrPage(String currPage) {
this.currPage = currPage;
} /**
* 返回
* @return
*/
public String getTotalPage() {
return totalPage;
} /**
* 设置
* @param
*/
public void setTotalPage(String totalPage) {
this.totalPage = totalPage;
} /**
* 返回
* @return
*/
public String getPageMax() {
return pageMax;
} /**
* 设置
* @param
*/
public void setPageMax(String pageMax) {
this.pageMax = pageMax;
} /**
* 返回
* @return
*/
public String getCount() {
return count;
} /**
* 设置
* @param
*/
public void setCount(String count) {
this.count = count;
} @Override
public void doTag() throws JspException, IOException {
JspWriter write = getJspContext().getOut();
StringBuffer sb = new StringBuffer();
sb.append("<div>")
.append("<button name=\"first\"><<</button>")
.append("<button name=\"pre\"><</button>")
.append("<input type=\"text\" name=\"inputName\" style=\"width: 45px;\"/>")
.append("<label>"+getValueFromStack(this.getCurrPage())+"/共"+getValueFromStack(this.getTotalPage())+"</label>")
.append("<button name=\"next\">></button>")
.append("<button name=\"last\">>></button>")
.append("<div>");
write.write(sb.toString());
} /**
* 在值栈中取出值
* @param str
* @return
*/
private String getValueFromStack(String str){
//取出时不要加%{},直接是存放在值栈中的变量名,此处获取到str是从页面标签传过的值,jia
//加%{}用以区分这个是从值栈中取出,对于不加%{}的属性表示表单提交的变量名称 相当于<input 中的 name属性
//action中的get方法名与之相同,则可获取由标签传递的值
if(str.startsWith("%{")){
str = str.substring(2,str.length()-1);
}
return (String) ActionContext.getContext().getValueStack().findValue(str);
} }

3、在jsp页面引用改标签

OK!!!

struts2的分页标签的更多相关文章

  1. Struts2自定义标签4自定义分页标签

    第一步:webroot/web-inf下的str.tld文件 <?xml version="1.0" encoding="UTF-8"?> < ...

  2. Struts2的OGNL标签详解

    一.Struts2可以将所有标签分成3类: UI标签:主要用于生成HTML元素的标签. 非UI标签:主要用于数据库访问,逻辑控制等标签. Ajax标签:用于Ajax支持的标签. 对于UI标签,则有可以 ...

  3. Struts2 实现分页

    1.转自:http://www.cnblogs.com/shiyangxt/archive/2008/11/04/1316737.html环境:MyEclipse6.5+Mysql5+struts2. ...

  4. NET Core-TagHelper实现分页标签

    这里将要和大家分享的是学习总结使用TagHelper实现分页标签,之前分享过一篇使用HtmlHelper扩展了一个分页写法地址可以点击这里http://www.cnblogs.com/wangrudo ...

  5. struts2 s:if标签以及 #,%{},%{#}的使用方法

    <s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...

  6. SSH自定义分页标签

    本文参考文章:http://blog.csdn.net/qjyong/article/details/3240303 一.标签处理类: package cn.conris.sys.form; impo ...

  7. struts2 if正确标签示例

    下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...

  8. struts2 s:if标签以及 #,%{},%{#}的使用方法等在资料整理

    <s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...

  9. struts2<s:property />标签

    struts2的<property />标签是输出标签 其value属性是指定输出的内容,如果value属性没有写出来,则默认输出对象栈栈顶的元素. 例如,我们在对象栈中添加一个Perso ...

随机推荐

  1. Timeout watchdog using a standby thread

    http://codereview.stackexchange.com/questions/84697/timeout-watchdog-using-a-standby-thread he simpl ...

  2. [Cocoa]深入浅出Cocoa多线程编程之 block 与 dispatch quene

    深入浅出 Cocoa 多线程编程之 block 与 dispatch quene 罗朝辉(http://www.cppblog.com/kesalin CC 许可,转载请注明出处 block 是 Ap ...

  3. [置顶] django快速获取项目所有的URL

    django快速获取项目所有的URL django1.10快速获取项目所有的URL列表,可以用于权限控制 函数如下: import re def get_url(urllist , parent='' ...

  4. DotnetBrowser入门教程-(2)启动简单的Web服务

    微软的网页服务向来与IIS捆绑紧密,虽然.net core可以脱离iis了,但是基于国内的xp系统,.net core类库的精简,使得我们仍然在dotnetbrowser增加了对web服务的支持. 先 ...

  5. Linux 设备驱动模型

    Linux系统将设备和驱动归一到设备驱动模型中了来管理 设备驱动程序功能: 1,对硬件设备初始化和释放 2,对设备进行管理,包括实参设置,以及提供对设备的统一操作接口 3,读取应用程序传递给设备文件的 ...

  6. CLI/C++中混合类的使用【转】

    http://www.cppblog.com/mzty/archive/2007/12/24/39517.html CLI/C++中混合类的使用 一 混合类 所谓混合类是指CLI/C++中native ...

  7. android ANR产生原因和解决的方法

    ANR (Application Not Responding) ANR定义:在Android上,假设你的应用程序有一段时间响应不够灵敏,系统会向用户显示一个对话框.这个对话框称作应用程序无响应(AN ...

  8. Notification(二)——PendingIntent的flag导致数据同样的问题

    MainActivity例如以下: package cc.cu; import android.os.Bundle; import android.view.View; import android. ...

  9. mysql下监测数据库语句creating sort index时间过长的问题

    在一张单表5000W数据上进行数据查询时传入两个单列索引条件,进行组合索引查询时,如果最后有order by id排序,与去除该排序,性能差距接近两个数量级 结论:在使用列的默认排序时,不应该再ord ...

  10. struts2学习笔记2 -struts2的开发步骤和工作原理

    struts2的开发步骤: 1.先定义一个能发送请求的页面,可以是链接,也可以是表单(form) 2.开发action类,struts2对action并没有过多的要求,只要求: a 推荐实现actio ...