prevformtag.java

来自「一个免费wap站」· Java 代码 · 共 80 行

JAVA
80
字号
package com.eline.wap.common.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.jsp.JspTagException;
import java.io.IOException;
import javax.servlet.jsp.JspWriter;

/**
 * 
 * @author Lucifer
 *
 */
public class PrevFormTag extends TagSupport {

	private static final long serialVersionUID = 6123778929643047239L;

    private String action;
    private String method;
    private ListTag listTag;

    public PrevFormTag() {
        this.action = null;
        this.method = "POST";
	}

    /**
     * 
     */
	public int doStartTag() throws JspException {
        listTag = (ListTag)TagSupport.findAncestorWithClass(this, ListTag.class);
        if(listTag == null)
            throw new JspTagException("PrevFormTag: prevForm tag not inside in listTag");
        if(!listTag.hasPreviousForm())
            return SKIP_BODY;
        if(listTag.pageIndex <= 0)
            return SKIP_BODY;

        try {
			JspWriter jspWriter = pageContext.getOut();
			jspWriter.println("<form method=\"" + method + "\" action=\"" + action + "\">");
			jspWriter.println("	<input type=\"hidden\" name=\"" + listTag.getParamPrefix() + listTag.getPageIndexParam() + "\" value=\"" + (listTag.getPageIndex() - 1) + "\" />");
			jspWriter.println("	<input type=\"hidden\" name=\"" + listTag.getParamPrefix() + listTag.getPrevParam() + "\" value=\"true\" />");
		} catch (IOException ioexception) {
			System.out.print("PrevFormTag: error printing <form> tag");
		}
		return EVAL_BODY_INCLUDE;
	}

	/**
	 * 
	 */
	public int doEndTag() throws JspException {
        if(listTag.hasPreviousForm()) {
            try {
                JspWriter jspWriter = pageContext.getOut();
                jspWriter.print("</form>");
            } catch (IOException e) {
                System.out.print("PrevFormTag: error printing <form> tag");
            }
        }
        return EVAL_PAGE;
	}

	/**
	 * 
	 * @param action
	 */
	public void setAction(String action) {
		this.action = action;
	}

	public void setMethod(String method) {
		if(method != null && !method.equals("") && !method.equalsIgnoreCase("null"))
			this.method = method;
		else
			this.method = "POST";
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?