📄 numberformtag.java
字号:
package com.eline.common.taglib;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.blue.web.common.util.AppLogger;
/**
* 显示指定页数
* @author Lucifer
* @version 1.0
*/
public class NumberFormTag extends TagSupport {
private static final long serialVersionUID = -4413167264546532053L;
private String action = null;
private ListTag listTag = null;
private int goPage = 0; //所转到的页数
/**
*
* @throws JspException
*/
public int doEndTag() throws JspException {
try {
JspWriter out = pageContext.getOut();
out.print("</form>");
} catch (IOException ex) {
AppLogger.error("NumberFormTag.doEndTag(): 产生转到指定页标记错误!");
}
return EVAL_PAGE;
}
/**
*
* @throws JspException
*/
public int doStartTag() throws JspException {
//验证其必须在列表标记内
listTag = (ListTag) findAncestorWithClass(this, ListTag.class);
if (listTag == null) {
throw new JspTagException("转到指定页标记不在列表标记内!");
}
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
if (request.getParameter(listTag.getParamPrefix() + "goPage")!=null && !request.getParameter(listTag.getParamPrefix() + "goPage").equals(""))
goPage = Integer.parseInt(request.getParameter(listTag.getParamPrefix() + "goPage").trim());
else
goPage = 1;
if (goPage < 1) //如果小于第一页则取其为第一页
goPage = 1;
else if (goPage > listTag.totalPages) //若大于最后一页则取最后一页
goPage = listTag.totalPages;
try {
JspWriter out = pageContext.getOut();
out.println("<form method=\"" + request.getMethod() + "\" action=\"" + action + "\">");
out.println(" <input type=\"hidden\" name=\"" + listTag.getParamPrefix() + listTag.getPageIndexParam() + "\" value=\"" + (goPage-1) + "\" />");
out.println(" <input type=\"hidden\" name=\"" + listTag.getParamPrefix() + listTag.getPrevParam() + "\" value=\"true\" />");
out.println(" <input type=\"text\" name=\"" + listTag.getParamPrefix() + "goPage\" value=\"" + goPage + "\" />");
} catch (IOException e) {
AppLogger.error("NumberFormTag.doStartTag() : 产生转到指定页标记错误!");
}
return EVAL_BODY_INCLUDE;
}
public void setAction(String action) {
this.action = action;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -