- 新建HelloWelTag类
- 如何添加jsp-api.jar包
- HelloWelTag类详细代码123456789101112131415161718192021222324252627package bid.zhazhapan.fims.tag;import java.io.IOException;import javax.servlet.jsp.JspException;import javax.servlet.jsp.tagext.TagSupport;public class HelloWelTag extends TagSupport {private String name;// 定义对应标签的属性// 通过set方法从页面获得name的属性值public void setName(String name) {this.name = name;}// 覆盖doEndTag()方法public int doEndTag() throws JspException {try {// 通过pageContext对象获得页面隐式对象out,向客户端输出结果pageContext.getOut().write("Welcome " + name);} catch (IOException e) {e.printStackTrace();new JspException("IO Error" + e.getMessage());}return this.EVAL_PAGE;}}
- 如何配置xml
- 新建test.jsp来测试标签123456789101112131415<!-- test.jsp详细代码 --><%@ page language="java" contentType="text/html; charset=ISO-8859-1"pageEncoding="ISO-8859-1"%><%@ taglib uri="WEB-INF/tlds/mytag.tld" prefix="mytag" %><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><mytag:welcome name="<%=\"Tony\" %>" /></body></html><!-- 输出结果:Welcome Tony -->
|
|