struts2的分页标签
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的分页标签的更多相关文章
- Struts2自定义标签4自定义分页标签
第一步:webroot/web-inf下的str.tld文件 <?xml version="1.0" encoding="UTF-8"?> < ...
- Struts2的OGNL标签详解
一.Struts2可以将所有标签分成3类: UI标签:主要用于生成HTML元素的标签. 非UI标签:主要用于数据库访问,逻辑控制等标签. Ajax标签:用于Ajax支持的标签. 对于UI标签,则有可以 ...
- Struts2 实现分页
1.转自:http://www.cnblogs.com/shiyangxt/archive/2008/11/04/1316737.html环境:MyEclipse6.5+Mysql5+struts2. ...
- NET Core-TagHelper实现分页标签
这里将要和大家分享的是学习总结使用TagHelper实现分页标签,之前分享过一篇使用HtmlHelper扩展了一个分页写法地址可以点击这里http://www.cnblogs.com/wangrudo ...
- struts2 s:if标签以及 #,%{},%{#}的使用方法
<s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...
- SSH自定义分页标签
本文参考文章:http://blog.csdn.net/qjyong/article/details/3240303 一.标签处理类: package cn.conris.sys.form; impo ...
- struts2 if正确标签示例
下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...
- struts2 s:if标签以及 #,%{},%{#}的使用方法等在资料整理
<s:if>判断字符串的问题: 1.判断单个字符:<s:if test="#session.user.username=='c'"> 这样是从session ...
- struts2<s:property />标签
struts2的<property />标签是输出标签 其value属性是指定输出的内容,如果value属性没有写出来,则默认输出对象栈栈顶的元素. 例如,我们在对象栈中添加一个Perso ...
随机推荐
- Educational Codeforces Round 34 A. Hungry Student Problem【枚举】
A. Hungry Student Problem time limit per test 1 second memory limit per test 256 megabytes input sta ...
- java的架构流行阶段
第一阶段:SSM 第二阶段:分布式系统改造,平台化初具规模,各项垂直业务系统搭建上线.产品端极大丰富用户投资.大数据平台研究并使用 第三阶段:SOA治理,使用zookeeper作为注册中心,dubbo ...
- 10.1综合强化刷题 Day4
财富(treasure) Time Limit:1000ms Memory Limit:128MB 题目描述 LYK有n个小伙伴.每个小伙伴有一个身高hi. 这个游戏是这样的,LYK生活的环境是以 ...
- 2016北京集训测试赛(十一)Problem C: 树链问题
Solution 智障暴力题, 每个点维护一下子树信息, 树剖就好了. 我居然还傻了写了一发毛毛虫... #include <cstdio> #include <cctype> ...
- Laravel 时间处理
$info['date'] = $item->created_at->diffForHumans();//友好时间显示 $info['date'] = $item->created_ ...
- Can''t find the channel handler for deviceType 工行 个人网银 错误
背景描述:系统Win7,浏览器IE8.登录工商银行个人网银的时候,输入帐号密码和验证码后,出现空白页面,上面一句话 Can''t find the channel handler for devic ...
- 做dg时遇到的log_archive_dest、log_archive_dest_1、db_recovery_file_dest之间互相影响
前提:归档开启.默认不指定归档文件夹. 今晚遇到客户那里设置了闪回区和log_archive_dest.不停库做DG时,无法指定log_archive_dest_n參数,巨坑. .实验了下.结论例如以 ...
- JAVA Eclipse 创建android xml看不到预览怎么办
电机安卓图标,设置为更低的API版本即可
- vue1和vue2获取dom元素的方法 及 nextTick() 、$nextTick()
vue1.*版本中 在标签中加上el='dom',然后在代码中this.$els.dom这样就拿到了页面元素 例如:<div class='box' el='myBox'>你好</d ...
- sublime添加sass编译
首先安装Ruby环境sass是基于ruby的产物,因此在安装sass前需要先安装ruby,如果用命令方式编译Sass也是必须安装ruby的.命令行编译sass见!下载Ruby windows 安装包: ...