JSP自定义标签,在线等

crossfirez 2011-05-11 03:44:47
JSP自定义的标签怎么让属性不用写等号,比如 <td>的nowrap可以写成<td nowrap>,
...全文
74 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
哈哈哈3234 2011-05-13
  • 打赏
  • 举报
回复
<?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/j2ee/dtd/web-jsptaglibrary_1_2.dtd">

<!-- a tag library descriptor -->

<taglib>
<tlib-version>1.0</tlib-version>
<jsp-version>1.2</jsp-version>
<short-name>debug</short-name>
<uri>http://http://www.accp.org/taglib</uri>
<description>
This tag library defines no tags. Instead, its purpose is
encapsulated in the TagLibraryValidator implementation that
simply outputs the XML version of a JSP page to standard output,
whenever this tag library is referenced in a "taglib" directive
in a JSP page.
</description>


<!-- This is a dummy tag solely to satisfy DTD requirements -->
<tag>
<name>roleRight</name>
<tag-class>com.company.wxxhccg.web.action.RoleTag</tag-class>
<description>
judge the role.
</description>
<attribute>
<name>urlInfo</name>
<required>true</required>
</attribute>
</tag>


</taglib>


package com.company.wxxhccg.web.action;

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

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

import com.company.wxxhccg.entity.ShoppingRoleRight;

public class RoleTag extends BodyTagSupport {
/**
*
*/
private static final long serialVersionUID = -7756422223877699970L;

private String urlInfo;

@Override
public int doStartTag() throws JspException {
List roleRightList = (List) pageContext.getSession().getAttribute("a");
System.out.println("系统url="+urlInfo);
try {
boolean isIn = false;
for (int i = 0; i < roleRightList.size(); i++) {
ShoppingRoleRight roleRight = (ShoppingRoleRight) roleRightList
.get(i);
//System.out.println("********"+urlInfo+"="+roleRight.getSysFun().getNodeUrl());
if (this.urlInfo.equals(roleRight.getSysFun().getNodeUrl())) {
// pageContext.getOut().print(" style='display:none' ");
// return SKIP_BODY;
isIn = true;
break;
}
}
if (!isIn) {
pageContext.getOut().print(" style='display:none' ");
return SKIP_BODY;
}
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
return SKIP_BODY;
}

public String getUrlInfo() {
return urlInfo;
}

public void setUrlInfo(String urlInfo) {
this.urlInfo = urlInfo;
}

}
zhangsanja 2011-05-12
  • 打赏
  • 举报
回复
自定义标签的属性,需要在tld文件中声明,也需要在标签类中添加相应属性,比较严格,不能省略。
chiese_fish 2011-05-12
  • 打赏
  • 举报
回复
我顶楼上的
hly_886 2011-05-11
  • 打赏
  • 举报
回复
可以直接加,html的标签可以直接加属性,没有的属性也可以,自定义的标签貌似不行
如 <td xxxx='1234' id='td1'> 通过 document.getElementById('td1').xxxx
可以得到xxxx的值是1234

81,114

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧