自定义标签的示例

自定义标签处理配置文件
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
"http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>self</short-name>
<uri>http://bonc.com/group-tag</uri>
<display-name>SELF core</display-name>
<description>Self 1.0 core library</description>


<tag>
<name>groupNavigate</name>
<tag-class>com.bonc.tag.GroupTag</tag-class>
<body-content>empty</body-content>
<description> </description>
<attribute>
<name>groupselect</name>
<required>false</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>

</taglib>


自定义标签处理类:
package com.bonc.tag;

import java.io.IOException;
import java.util.List;

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

import com.bonc.dao.TempDimGroupinfo;
import com.bonc.dao.TempDimGroupinfoDAO;

public class GroupTag extends TagSupport {

String groupselect="";

public String getGroupselect() {
return groupselect;
}


public void setGroupselect(String groupselect) {
this.groupselect = groupselect;
}


public int doEndTag() throws JspException {
return super.EVAL_BODY_INCLUDE;
}


public int doStartTag() throws JspException {

ServletRequest request = pageContext.getRequest();
//String groupsel = (String) request.getAttribute("groupsel");
String groupid = (String) request.getAttribute("groupid");

String html="";
TempDimGroupinfoDAO dao = new TempDimGroupinfoDAO();
TempDimGroupinfo groupinfo = new TempDimGroupinfo();
List list = dao.findAll();
html="<select name=\"groupidsel\">";
for(int i=0;i<list.size();i++)
{
groupinfo = (TempDimGroupinfo) list.get(i);

if(groupid==null){
html+="<option value=\""+groupinfo.getGroupId()+"\">"+groupinfo.getGroupName()+"</option>";
}else
{
if(groupid.equals(groupinfo.getGroupId())){
html+="<option value=\""+groupinfo.getGroupId()+"\" selected>"+groupinfo.getGroupName()+"</option>";
}
else{
html+="<option value=\""+groupinfo.getGroupId()+"\">"+groupinfo.getGroupName()+"</option>";
}
}

}
html+="</select>";
html+="<input type=\"hidden\" name=\"groupid\" value=\""+groupid+"\">";

try {
pageContext.getOut().write(html);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return super.EVAL_PAGE;
}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值