htmltag.java

来自「管理公司合同」· Java 代码 · 共 120 行

JAVA
120
字号
/*
 * Created on 2006-7-4 17:07:43
 *
 * By SinoBest
 * Copyright hnisi.com.cn, 2005-2006, All rights reserved.
 */

package cn.com.juneng.system.common.taglib;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

/**
 * @author yehailong
 * 
 */

public class HtmlTag extends BodyTagSupport {
	private final static long serialVersionUID = 0;


	private Map attributeMap = new HashMap();

	public void setAttribute(String key, String value) {
		this.attributeMap.put(key, value);
	}

	public String getAttribute(String key) {
		return (String) this.attributeMap.get(key);
	}

	public int getAttributeCount() {
		return this.attributeMap.keySet().size();
	}

	public String getHtmlAttribute() {
		StringBuffer sb = new StringBuffer(" ");
		for (Iterator it = this.attributeMap.keySet().iterator(); it.hasNext();) {
			String key = it.next().toString();
			sb.append(key).append("=").append("\"").append(
					attributeMap.get(key)).append("\" ");
		}
		return sb.toString();
	}

	public void release() {
		this.attributeMap.clear();
		super.release();
	}

	public Map getAttributeMap() {
		return this.attributeMap;
	}

	public HttpServletRequest request() {
		return (HttpServletRequest) this.pageContext.getRequest();
	}

	public HttpServletResponse response() {
		return (HttpServletResponse) this.pageContext.getResponse();
	}

	public HttpSession session() {
		return request().getSession();
	}

	public JspWriter out() {
		return this.pageContext.getOut();
	}

	private JspWriter output;

	public JspWriter getOutput() {
		// if(output == null){
		// output = this.pageContext.getOut();
		// }
		return this.pageContext.getOut();
	}

	public JspWriter println(Object text) throws JspException {
		JspWriter output = this.getOutput();
		try {
			output.println(text);
			return output;
		} catch (IOException e) {
			throw new JspException(e);
		}
	}

	public JspWriter print(Object text) throws JspException {
		JspWriter output = this.getOutput();
		try {
			output.print(text);
			return output;
		} catch (IOException e) {
			throw new JspException(e);
		}
	}

	protected JspWriter printInput(String type, String name, String value)
			throws JspException {
		return println("<input type='" + type + "' name='" + name + "' id='"
				+ name + "' value='" + value + "' >");
	}

	protected JspWriter printTd(String text) throws JspException {
		return println("<td>" + text + "</td>");
	}

}

⌨️ 快捷键说明

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