wmlprevformtag.java

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

JAVA
121
字号
package com.eline.wap.common.taglib.wml;

import java.util.StringTokenizer;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
import com.eline.wap.common.taglib.ListTag;
import com.eline.wap.common.util.AppLogger;

public class WmlPrevFormTag extends TagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = -7136240367972584962L;

    private String action = null;
    private ListTag listTag = null;
    private String method = "post";

    /**
     * 
     * throws JspException
     */
	public int doEndTag() throws JspException {
	    // if the start index isn't already at 1, print out </form> tag
	    if (listTag.hasPreviousForm()) {
	      try {
	       JspWriter out = pageContext.getOut();
	       out.print("</go>");
	       out.print("</anchor>&nbsp;");
	      } catch(IOException ioe) {
	    	  AppLogger.error("WmlPrevFormTag.doEndTag(): 形成上一页标记WmlPrevFormTag失败!");
	      }
	    }
	    return EVAL_PAGE;
	}

	/**
	 * 
	 * @throws JspException
	 */
	public int doStartTag() throws JspException {
        // check if inside list tag
        listTag = (ListTag) findAncestorWithClass(this, ListTag.class);
        if (listTag == null) {
            throw new JspTagException("PrevFormTag: prevForm tag not inside list" + "tag");
        }
        
        // if the start index is already at 1, don't need a prev form
        if (!listTag.hasPreviousForm())
        	return SKIP_BODY;

        if (listTag.getPageIndex() < 1)
            return SKIP_BODY;

        try {
        	JspWriter out = pageContext.getOut();
            //求出所要转到的网页
            StringTokenizer actionToken = new StringTokenizer(action, "?");
            if (actionToken.countTokens() < 1) {
                throw new JspTagException("所传入链接不合法!");
            }
            String linkURL = actionToken.nextToken();
            String paramsList = "";
            if (actionToken.countTokens() > 0) {
            	paramsList = actionToken.nextToken();
            }

            //求出页面中传过来的参数串
            StringTokenizer paramsToken = new StringTokenizer(paramsList, "&");
            String itemStr = null, param = null, value = null;
            StringTokenizer itemToken = null;

            //形成参数传递页面内容
            out.print("<anchor>上页");
            // out.print("<go href=\"" + linkURL + "\">");
			out.print("<go href=\"" + linkURL + "\" method=\"" + this.method + "\">");

            // 页面相关参数
            out.print("<postfield name=\"" + listTag.getParamPrefix() + listTag.getPageIndexParam() + "\" value=\"" + (listTag.getPageIndex() - 1) + "\" />");
            out.print("<postfield name=\"" + listTag.getParamPrefix() + listTag.getPrevParam() + "\" value=\"true\" />");
            
            // 原始参数
            while (paramsToken.hasMoreTokens()) {
                itemStr = paramsToken.nextToken();
                itemToken = new StringTokenizer(itemStr, "=");
                if (itemToken.countTokens() > 1) {
                    param = itemToken.nextToken();
                    if (param.indexOf("amp;") >= 0) {
                        param = param.substring(4);
                    }
                    value = itemToken.nextToken();
                    out.print("<postfield name=\"" + param + "\" value=\"" + value + "\" />");
                }
            }
        } catch (IOException e) {
        	AppLogger.error("WmlPrevFormTag.doStartTag(): 形成上一页标记WmlPrevFormTag失败!");
        }

        return EVAL_BODY_INCLUDE;
	}

	/**
	 * 
	 * @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 + -
显示快捷键?