下面是struts自带的linkTAG的源代码(get和set方法已略)
你自己看看吧:
(里面的calculateURL和static Class class$(String x0)方法我没能看懂
如果你有什么心得,记得告诉我一声,^_^,谢了!)
package org.apache.struts.taglib.html;import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyContent;
import javax.servlet.jsp.tagext.TagSupport;
import org.apache.struts.taglib.logic.IterateTag;
import org.apache.struts.util.*;public class LinkTag extends BaseHandlerTag
{    protected String text;
    protected String anchor;
    protected String forward;
    protected String href;
    protected String linkName;
    protected static MessageResources messages = MessageResources.getMessageResources("org.apache.struts.taglib.html.LocalStrings");
    protected String name;
    protected String page;
    protected String action;
    protected String paramId;
    protected String paramName;
    protected String paramProperty;
    protected String paramScope;
    protected String property;
    protected String scope;
    protected String target;
    protected boolean transaction;
    protected String indexId;
    static Class class$org$apache$struts$taglib$logic$IterateTag; /* synthetic field */    public LinkTag()
    {
        text = null;
        anchor = null;
        forward = null;
        href = null;
        linkName = null;
        name = null;
        page = null;
        action = null;
        paramId = null;
        paramName = null;
        paramProperty = null;
        paramScope = null;
        property = null;
        scope = null;
        target = null;
        transaction = false;
        indexId = null;
    }        public int doStartTag() throws JspException
    {
        StringBuffer results;
        if(linkName != null)
        {
            results = new StringBuffer("<a name=\"");
            results.append(linkName);
            results.append("\">");
            ResponseUtils.write(pageContext, results.toString());
            return 2;
        }
        results = new StringBuffer("<a href=\"");
        results.append(calculateURL());
        results.append("\"");
        if(target != null)
        {
            results.append(" target=\"");
            results.append(target);
            results.append("\"");
        }
        if(accesskey != null)
        {
            results.append(" accesskey=\"");
            results.append(accesskey);
            results.append("\"");
        }
        if(tabindex != null)
        {
            results.append(" tabindex=\"");
            results.append(tabindex);
            results.append("\"");
        }
        results.append(prepareStyles());
        results.append(prepareEventHandlers());
        results.append(">");
        ResponseUtils.write(pageContext, results.toString());
        text = null;
        return 2;
    }    public int doAfterBody()
        throws JspException
    {
        if(bodyContent != null)
        {
            String value = bodyContent.getString().trim();
            if(value.length() > 0)
                text = value;
        }
        return 0;
    }    public int doEndTag()
        throws JspException
    {
        StringBuffer results = new StringBuffer();
        if(text != null)
            results.append(text);
        results.append("</a>");
        ResponseUtils.write(pageContext, results.toString());
        return 6;
    }    public void release()
    {
        super.release();
        anchor = null;
        forward = null;
        href = null;
        linkName = null;
        name = null;
        page = null;
        action = null;
        paramId = null;
        paramName = null;
        paramProperty = null;
        paramScope = null;
        property = null;
        scope = null;
        target = null;
        text = null;
        transaction = false;
    }    protected String calculateURL()
        throws JspException
    {
        Map params = RequestUtils.computeParameters(pageContext, paramId, paramName, paramProperty, paramScope, name, property, scope, transaction);
        if(indexed)
        {
            IterateTag iterateTag = (IterateTag)TagSupport.findAncestorWithClass(this, class$org$apache$struts$taglib$logic$IterateTag != null ? class$org$apache$struts$taglib$logic$IterateTag : (class$org$apache$struts$taglib$logic$IterateTag = class$("org.apache.struts.taglib.logic.IterateTag")));
            if(iterateTag == null)
            {
                JspException e = new JspException(messages.getMessage("indexed.noEnclosingIterate"));
                RequestUtils.saveException(pageContext, e);
                throw e;
            }
            if(params == null)
                params = new HashMap();
            if(indexId != null)
                params.put(indexId, Integer.toString(iterateTag.getIndex()));
            else
                params.put("index", Integer.toString(iterateTag.getIndex()));
        }
        String url = null;
        try
        {
            url = RequestUtils.computeURL(pageContext, forward, href, page, action, params, anchor, false);
        }
        catch(MalformedURLException e)
        {
            RequestUtils.saveException(pageContext, e);
            throw new JspException(messages.getMessage("rewrite.url", e.toString()));
        }
        return url;
    }    static Class class$(String x0)
    {
        return Class.forName(x0);
        ClassNotFoundException x1;
        x1;
        throw new NoClassDefFoundError(x1.getMessage());
    }}