elementoutputtag.java

来自「J2EE独立开发制作」· Java 代码 · 共 40 行

JAVA
40
字号
package diegoyun;
import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.beanutils.PropertyUtils;

public class ElementOutputTag extends TagSupport
{
	private Object propertyValue = null;
	private String property=null;
	public void setProperty(String property)throws JspException
	{
		WithCollectionTag parent = (WithCollectionTag)getParent();
		if(parent == null)throw new JspException("parent tag is null");
		try
		{
			//判断上层tag中是否存在该属性名称,如果存在,取得属性值,否则报错
propertyValue = PropertyUtils.getProperty(parent.getElement(), property);
}
catch (Exception e)
{
throw new JspException(e);
}
}
public int doEndTag()throws JspException
{
try
{
//简单的把值打印到jsp页面
pageContext.getOut().print(propertyValue);
}
catch (IOException e)
{
throw new JspException(e);
}
return EVAL_PAGE;
}
}

⌨️ 快捷键说明

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