apache commons lang3 stringutils taglib(apache commons lang3 stringutils taglib)

编程入门 行业动态 更新时间:2024-10-25 19:22:49
apache commons lang3 stringutils taglib(apache commons lang3 stringutils taglib)

我喜欢在jstl标签中使用StringUtils.abbreviate(),是否有taglib位置?

我搜索了公共网站和网站,但无法找到一个例子。 是否有一种常见的方法来查找taglib位置,也许在javadoc树的标准位置?

谢谢! 尼克

Id like to use StringUtils.abbreviate() inside a jstl tag, is there a taglib location for this?

Ive searched the commons site and the web but an unable to find an example. Is there a common way to find taglib locations also, maybe in a standard location of a javadoc tree??

Thanks! Nic

最满意答案

尼克,

通常没有预定义的标签来获取apache util方法,但是很容易添加自己的特殊标记定义来指向您想要的方法。 例如,将本地taglib定义添加到web.xml文件中:

<jsp-config> <taglib> <taglib-uri>mytags</taglib-uri> <taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location> </taglib> </jsp-config>

你的mytaglib.tld文件看起来像这样:

<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tlib-version>1.0</tlib-version> <function> <description>Exposes the abbreviate() function from Apache StringUtils</description> <name>abbreviate</name> <function-class>org.apache.commons.lang.StringUtils</function-class> <function-signature>java.lang.String abbreviate(java.lang.String, int)</function-signature> </function> </taglib>

在JSP中,您可以使用新的自定义标记:

<%@ taglib prefix="mytags" uri="mytags" %> ... <c:out value="${mytags:abbreviate(myString, 5)"/>

那应该为你做。 有关自定义标签的更多信息,请参阅此处: http : //docs.oracle.com/javaee/5/tutorial/doc/bnalj.html

Nic,

There often isn't a predefined tag to get at the apache util methods, but it's easy to add your own special tag definitions to point to the method you want. For example, add a local taglib definition to your web.xml file:

<jsp-config> <taglib> <taglib-uri>mytags</taglib-uri> <taglib-location>/WEB-INF/jsp/mytaglib.tld</taglib-location> </taglib> </jsp-config>

Your mytaglib.tld file will look something like this:

<?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <tlib-version>1.0</tlib-version> <function> <description>Exposes the abbreviate() function from Apache StringUtils</description> <name>abbreviate</name> <function-class>org.apache.commons.lang.StringUtils</function-class> <function-signature>java.lang.String abbreviate(java.lang.String, int)</function-signature> </function> </taglib>

In your JSP, you can then use your new custom tag:

<%@ taglib prefix="mytags" uri="mytags" %> ... <c:out value="${mytags:abbreviate(myString, 5)"/>

That should do it for you. For more info on custom tags, you can read here: http://docs.oracle.com/javaee/5/tutorial/doc/bnalj.html

更多推荐

本文发布于:2023-07-14 23:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1108347.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:commons   apache   taglib   stringutils

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!