自定义tag

OutputTag

package diegoyun;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;
/**
* @author chenys
*/
public class OutputTag extends TagSupport
{
private String name=null;
public void setName(String name)
{
this.name = name;
}

public int doStartTag() throws JspException{
try
{
JspWriter out = pageContext.getOut();
out.print("Hello! " + name);
}
catch (Exception e)
{
throw new JspException(e);
}
return EVAL_PAGE;
}
}

  简要说明:

  1、如何输出到jsp页面:

  调用JspWriter JspWriter out = pageContext.getOut();out.print......

  记住这个方法就可以了。

你可能感兴趣的:(jsp,servlet)