web.xml 中这样配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Apache-Axis</display-name>
<!--计生险 标签配置-->
<taglib>
<taglib-uri>/eservice</taglib-uri>
<taglib-location>/WEB-INF/tld/eservice.tld</taglib-location>
</taglib>
<!-- 计生险 配置 MVC CONTROL servlet -->
<context-param>
<param-name>
servletConfig
</param-name>
<param-value>
/WEB-INF/xmlconfig/servlet.xml
</param-value>
</context-param>
eservice.tld 中这样配置
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd">
<description></description>
<display-name></display-name>
<tlib-version>1.0</tlib-version>
<short-name>es</short-name>
<tag>
<name>showContent</name>
<tag-class>com.saleOnline.discount.tag.ShowContentTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>fk</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>key</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>pageName</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
实现类中这样写
package com.saleOnline.discount.tag;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.TagSupport;
import com.saleOnline.discount.service.DiscountService;
/**
*
* 描述:标签中静态常量:
* EVAL_BODY_INCLUDE:告诉服务器正文的内容,并把这些内容送入输出流。
* SKIP_BODY:告诉服务器不要处理正文内容。
* EVAL_PAGE:让服务器继续执行页面。
* SKIP_PAGE:让服务器不要处理剩余的页面。
* EVAL_BODY_AGAIN:让服务器继续处理正文内容,只有doAfterBody方法可以返回。
* EVAL_BODY_BUFFERED:BodyTag接口的字段,在doStartTag()返回。
* EVAL_BODY_INCLUDE、SKIP_BODY一般由doStartTag()返回,而EVAL_PAPGE、返回
* @author Administrator
* 修改日期:2012-6-27下午02:27:39
* E-mail:
*/
public class ShowContentTag extends TagSupport {
private String fk;
private String key;
private String pageName;
public String getPageName(){
return pageName;
}
public void setPageName(String pageName){
this.pageName=pageName;
}
/**
*
* 描述:在结束标签之前调用,返回SKIP_PAGE跳过整个jsp页面后面的输出,返回EVAL_PAGE执行页面余下部分
* @author Administrator
* 修改日期:2012-6-27下午02:25:32
* @return
* @throws JspException
*/
public int doEndTag() throws JspException {
return EVAL_PAGE;
}
/**
*
* 描述:在开始标签属性设置后调用,如果返回SKIP_BODY则忽略标签之中的内容,如果返回EVAL_BODY_INCLUDE则将标签体的内容进行输出
* @author Administrator
* 修改日期:2012-6-27下午02:24:17
* @return
* @throws JspException
*/
public int doStartTag() throws JspException{
if(key==null||fk==null||pageName==null){
throw new JspException("必填字段为null");
}
DiscountService discountService=new DiscountService();
String context="";
//根据打折id,条目名,获取显示内容
context=discountService.getPageContentInfo(fk,key,pageName);
try{
pageContext.getOut().print(context);
}catch(IOException e){
// TODO Auto-generated catch block
e.printStackTrace();
}
return SKIP_BODY;
}
/**
*
* 描述:生命周期结束时调用
* @author Administrator
* 修改日期:2012-6-27下午02:26:45
*/
public void release() {
}
/**
*
* 描述:将所在jsp页面的pageContext注入进来,目的是为了在后面的方法中可以访问到jsp
* 页面对象的pageContext属性
* @author Administrator
* 修改日期:2012-6-27下午02:22:49
* @param pageContext
*/
public void setPageContext(PageContext pageContext) {
super.setPageContext(pageContext);
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFk(){
return fk;
}
public void setFk(String fk){
this.fk=fk;
}
public String getKey(){
return key;
}
public void setKey(String key){
this.key=key;
}
}
页面中这样引
<%@ taglib uri="/eservice" prefix="es" %>
<es:showContent pageName="addInfo" key="<%=DiscountService.DESC_FOR_INPUT_ADDRESS %>" fk="<%=actionsId %>"/>