首页 > 代码库 > 终极解法According to TLD or attribute directive in tag file, attribute select does not accept any expressions

终极解法According to TLD or attribute directive in tag file, attribute select does not accept any expressions

3天硬是是把这个问题解决了 有时候突然上个厕所灵感就来了

第一次向用JSTL解析xml 然后我想遍历整个xml文档打印出来

居然不让我输入变量 那让我怎么办啊

在网上各种找答案

说什么<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>变为:
<%@ taglib prefix="c" uri=http://java.sun.com/jstl/core_rt  %>

什么反应都没有啊 然后又上stackoverflow

也没有解决问题

突然灵感来了 我就去看它的源文件

 

这是eclipse自带的jstl包里面规定解析的地方

打开一看恍然大悟啊

一看就明白啊 原理解析的时候工具是从这找的配置文件

 

tag就是每个标签的配置文件 拿out举例子 红色部分声明的就是select这个属性能不能有变量  rtexpravlue意思就是“变量表达式”

 

现在好了 想办法把这个表达式改了就行了 直接改当然不得法 我们只要“欺骗”下工具就行了

1复制出来其中一个文件,比如x.tld,然后再本地修改,因为在工具里面文件只读

2将x.tld里面的你想要改的部分修改,比如我想让select属性有表达式 我就让上面红色的地方改成true

3在工程的web.xml声明这样一段话

    <jsp-config>        <taglib>            <taglib-uri>/huang</taglib-uri>            <taglib-location>/WEB-INF/x.tld</taglib-location>        </taglib>    </jsp-config>

4在具体的jsp页面引用这个你自己定义的"huang"新标签

<%@ taglib prefix="x" uri="/huang" %> 

5OK了,现在就可以用这个新标签来看你想干的事了

比如我现在就可以拼接变量了

比如以前我

select里面套变量的话就会报错According to TLD or attribute directive in tag file, attribute select does not accept any expressions

现在:

<x:out select="$casexml//案例//${node.name }" />

两个EL表达式搞定当然用<%=xx%>也可以了

显示正常

 

对了我的web版本是

 

<web-app version="3.0"     xmlns="http://java.sun.com/xml/ns/javaee"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

 

终极解法According to TLD or attribute directive in tag file, attribute select does not accept any expressions