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 ...
随机推荐
- Codeforces Gym101473 E.Dangerous Dive (2013-2014 ACM-ICPC Brazil Subregional Programming Contest)
代码: 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmat ...
- ui设计的好网站(转载)
设计师网址导航 http://hao.uisdc.com/ 站酷 国外: Dribbble - Show and tell for designers.Behance 这两个网站就够了啊 ————— ...
- Factory Method 和AbstractFactory
对应慕课视频的连接:https://www.imooc.com/video/5316 1,工厂模式的应用场景 有一组类似的对象需要被创建 在编码时不能预见需要被创建哪种类的实例 在系统需要考虑扩展性的 ...
- ORACLE普通表转换成分区表
转http://mp.weixin.qq.com/s?__biz=MzAwMjkyMjEwNg==&mid=2247484761&idx=1&sn=ce080581145931 ...
- ie8 不能加载dll的问题解决
请问是在打开IE的时候提示无法加载DLL文件吗? 请尝试重置IE: 1. 关闭所有Internet Explorer窗口. 2. 单击开始,点击运行,输入inetcpl.cpl,按回车. 3. 点击高 ...
- OWASP Dependency-Check插件介绍及使用
1.Dependency-Check可以检查项目依赖包存在的已知.公开披露的漏洞.目前良好的支持Java和.NET:Ruby.Node.js.Python处于实验阶段:仅支持通过(autoconf a ...
- Python scapy 实现一个简易 arp 攻击脚本
原文链接:http://www.jianshu.com/p/df5918069612 scapy 是 python 写的一个功能强大的交互式数据包处理程序,可用来发送.嗅探.解析和伪造网络数据包,常常 ...
- GPS整数。度分秒转换
例如30.453280 104.2018怎么把度数转换为度分秒的格式要详细换算方法 例如30.453280°,30.453280°,则有30°0.453280°×60= 27.1968′则有27′0. ...
- 【音乐App】—— Vue-music 项目学习笔记:用户个人中心开发
前言:以下内容均为学习慕课网高级实战课程的实践爬坑笔记. 项目github地址:https://github.com/66Web/ljq_vue_music,欢迎Star. 歌曲列表 收藏歌曲 一.用 ...
- linux中shell脚本中系统预先定义的变量
$0:脚本名称: $*:所有参数: $$:当前进程或者脚本的PID号: $!:后台运行的最后一个进程的PID号: $?:用于返回上一个命令是否成功.成功0,否则为非零: $#:参数个数: $@:所有参 ...