菜单 学习猿地 - LMONKEY

VIP

开通学习猿地VIP

尊享10项VIP特权 持续新增

知识通关挑战

打卡带练!告别无效练习

接私单赚外块

VIP优先接,累计金额超百万

学习猿地私房课免费学

大厂实战课仅对VIP开放

你的一对一导师

每月可免费咨询大牛30次

领取更多软件工程师实用特权

入驻
395
0

According to TLD or attribute directive in tag file, attribute sort does not accept any expressions

原创
05/13 14:22
阅读数 68708

自定义了一个标签,报错报如下:

According to TLD or attribute directive in tag file, attribute sort does not accept any expressions

意思:根据TLD或tag文件中的属性,属性“sort”不接受任何表达式

 

/*
*自定义了一个菜单标签
*/
public
class MenuTag extends SimpleTagSupport { private PageContext pageContext; private String contextPath; private String charset = "UTF-8"; private String imgPath = "manage/scripts/customMenu/menu/"; private StringBuffer html = new StringBuffer(""); private String shieldMenu = ReadConfigFileUtil.getValue("shieldMenu");// 要的屏蔽菜单名 private String sort; @SuppressWarnings("unchecked") @Override public void doTag() throws JspException, IOException { // 获取用户权限 HttpSession session = pageContext.getSession(); if (session.getAttribute("leftMenuHtml") == null || !String.valueOf(session.getAttribute("leftMenuSort")).equals(sort)) { contextPath = pageContext.getServletContext().getContextPath() + "/"; List<Resource> resources = (List<Resource>) session.getAttribute("userTopLevelMenuList"); List<Resource> subResource = new ArrayList<Resource>(); for (Resource ritem : resources) { if (ritem.getSort().equals(Integer.valueOf(sort))) { subResource.addAll(ritem.getChildrens()); } } html.append("<ul id=\"ulParent\">"); for (Resource r : subResource) { if (!shieldMenu.contains(";" + r.getName() + ";")) { html.append("<li class='liParent'><div class='divParent'>"); html.append("<img class='imgIcon' src='" + contextPath + imgPath + r.getIcon() + "'/>"); html.append("<img class='upOrDownHover' src='" + contextPath + imgPath + "downHover.png'/>"); html.append("<label>" + r.getName() + "</label></div>"); if (r.getChildrens() != null && r.getChildrens().size() > 0) { ArrayList<Resource> resourcess = new ArrayList<Resource>(r.getChildrens()); CommonUtil.getSortResource(resourcess); getChildrenMenu(resourcess, 2, "menu1Name=" + URLEncoder.encode(r.getName(), charset)); } html.append("</li>"); } } html.append("</ul>"); session.setAttribute("leftMenuHtml", html.toString()); session.setAttribute("leftMenuSort", sort); } pageContext.getOut().print((String) session.getAttribute("leftMenuHtml")); } /** * 组合下级菜单 * * @param set * @return * @throws IOException */ private void getChildrenMenu(List<Resource> resources, int level, String parentName) throws IOException { Iterator<Resource> it = resources.iterator(); while (it.hasNext()) { Resource r = it.next(); if (!SystemStatics.MARK_OPERATE.equals(r.getMark()) && !shieldMenu.contains(";" + r.getName() + ";")) { String name = parentName + "&amp;menu" + level + "Name=" + URLEncoder.encode(r.getName(), charset); String url = contextPath + r.getUrl() + "?" + name; html.append("<ul class='ulChild'><li class='liChild'>"); html.append("<div id='" + r.getId() + "' class='divChild'" + " style='padding-left:" + level * 8 + "px' " + "lang='" + r.getMark() + "' checkUrl='" + r.getUrl() + "' url='" + url + "'>"); if (SystemStatics.MARK_LINK.equals(r.getMark())) { html.append("<img class='imgIconSmall circle' src='" + contextPath + imgPath + "circle.png'/>"); } else { html.append("<img class='imgIconSmall plus' src='" + contextPath + imgPath + "plus.png'/>"); } html.append("<label>" + r.getName() + "</label></div>"); if (r.getChildrens() != null && r.getChildrens().size() > 0) { ArrayList<Resource> resourcess = new ArrayList<Resource>(r.getChildrens()); CommonUtil.getSortResource(resourcess); getChildrenMenu(resourcess, level + 1, name); } html.append("</li></ul>"); } } } @Override public void setJspContext(JspContext pc) { pageContext = (PageContext) pc; } public String getSort() { return sort; } public void setSort(String sort) { this.sort = sort; } }

在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>"Privilege Tags"</display-name>
    <tlib-version>1.0</tlib-version>
    <short-name>p</short-name>
    <tag>
        <description><![CDATA[menu tag]]></description>
        <name>menu</name>
        <tag-class>com.vrv.paw.tag.MenuTag</tag-class>
        <body-content>empty</body-content>
        <attribute>
            <name>sort</name>          
        </attribute>
    </tag>
</taglib>

错误原因就是:

理论:

 

发表评论

0/200
395 点赞
0 评论
收藏