自定义JSTL标签库(函数库)
来源:互联网 发布:梦里花落知多少名句 编辑:程序博客网 时间:2024/04/29 16:53
这个使用起来比较简单,不需要配置web.xml或者其它配置文件,但是可能需要在pom.xml中引入spring配置
另外,还有一套标准的函数库,但是要引入
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
如果不引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>,好像会出错的,要特别注意
比如<c:set var="myString" value="hello peter"/>
${fn:contains(myString, "hello")}
写peter.tld,
这里特别说明,<name>getTestString</name>一定要写成函数名,乱写是不能调用的; <short-name>peter</short-name>是写在:前面的,也要小心,这个文件要放在/WEB-INF/tlds/peter.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>JSTL 1.1 functions library</description>
<display-name>JSTL functions sys</display-name>
<tlib-version>1.1</tlib-version>
<short-name>peter</short-name>
<uri>http://java.sun.com/jsp/jstl/functionss</uri>
<function>
<description>test</description>
<name>getTestString</name>
<function-class>peter.web.demo.common.utils.FrontPageTest</function-class>
<function-signature>java.lang.String getTestString(java.lang.String)</function-signature>
<example>${peter:getAdminPath(str)}</example>
</function>
</taglib>
-----------------------------------------------------------------
完成jsp,这里要特别说明一下,
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="peter" uri="/WEB-INF/tlds/peter.tld" %>
这个要加好
<%@ page contentType="text/html;charset=UTF-8" %>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="peter" uri="/WEB-INF/tlds/peter.tld" %>
<html>
<head>
<title>BrchMng管理</title>
<meta name="decorator" content="default"/>
</head>
<body>
<form id="inputForm" action="${pageContext.request.contextPath}/login" method="post" class="form-horizontal">
<label> 111111111</label>
<label>${peter:getTestString("into hou")}</label>
<div class="form-actions">
<input id="btnSubmit" class="btn btn-primary" type="submit" value="登陆"/>
<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
</div>
</form>
</body>
</html>
--------------------------------------------------------
完成对应的类
package peter.web.demo.common.utils;
/**
* Created by Administrator on 2017-03-15.
*/
public class FrontPageTest {
public static String getTestString(String inStr )
{
System.out.println("inStr = " + inStr);
return "fffffffffffffff";
}
}
这个类没有什么需要配置的,但是,需要public静态函数,要不然,不好调用
另外,还有一套标准的函数库,但是要引入
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
如果不引入<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>,好像会出错的,要特别注意
比如<c:set var="myString" value="hello peter"/>
${fn:contains(myString, "hello")}
前台会显示true,如果不引入core,前台会false
js调用方法
<scripttype="text/javascript">
top.location.href='${fns:getProjectUrl()}/index.jsp';
</script>
还有一个问题要说,可能在编辑器里面http://java.sun.com/jsp/jstl/core是红的,我们也无法进入URL,但是没有问题的
-------------------------------------------------------------------写peter.tld,
这里特别说明,<name>getTestString</name>一定要写成函数名,乱写是不能调用的; <short-name>peter</short-name>是写在:前面的,也要小心,这个文件要放在/WEB-INF/tlds/peter.tld
<?xml version="1.0" encoding="UTF-8" ?>
<taglib xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
version="2.0">
<description>JSTL 1.1 functions library</description>
<display-name>JSTL functions sys</display-name>
<tlib-version>1.1</tlib-version>
<short-name>peter</short-name>
<uri>http://java.sun.com/jsp/jstl/functionss</uri>
<function>
<description>test</description>
<name>getTestString</name>
<function-class>peter.web.demo.common.utils.FrontPageTest</function-class>
<function-signature>java.lang.String getTestString(java.lang.String)</function-signature>
<example>${peter:getAdminPath(str)}</example>
</function>
</taglib>
-----------------------------------------------------------------
完成jsp,这里要特别说明一下,
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="peter" uri="/WEB-INF/tlds/peter.tld" %>
这个要加好
<%@ page contentType="text/html;charset=UTF-8" %>
<%--<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="peter" uri="/WEB-INF/tlds/peter.tld" %>
<html>
<head>
<title>BrchMng管理</title>
<meta name="decorator" content="default"/>
</head>
<body>
<form id="inputForm" action="${pageContext.request.contextPath}/login" method="post" class="form-horizontal">
<label> 111111111</label>
<label>${peter:getTestString("into hou")}</label>
<div class="form-actions">
<input id="btnSubmit" class="btn btn-primary" type="submit" value="登陆"/>
<input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
</div>
</form>
</body>
</html>
--------------------------------------------------------
完成对应的类
package peter.web.demo.common.utils;
/**
* Created by Administrator on 2017-03-15.
*/
public class FrontPageTest {
public static String getTestString(String inStr )
{
System.out.println("inStr = " + inStr);
return "fffffffffffffff";
}
}
这个类没有什么需要配置的,但是,需要public静态函数,要不然,不好调用
0 0
- 自定义JSTL标签库(函数库)
- jstl函数库及自定义函数库
- jstl函数库及自定义函数库
- java程序员第十三课-EL表达式、JSTL标签库、EL函数库、自定义EL函数和自定义标签
- 自定义jstl标签库
- 自定义jstl标签库
- 自定义 JSTL标签库
- jstl 自定义函数库
- JSTL 自定义函数库
- JSTL 自定义函数库
- 自定义JSTL函数库
- JSTL标签库,自定义标签
- 开发自定义 jstl标签库
- JSTL:自定义标签库 1
- JSTL自定义函数库的实现
- JSP自定义标签(2)JSTL标签库
- 自定义标签&JSTL标签库&EL函数
- 自定义标签&&JSTL标签库详解
- 从listView到RecyclerView,实战带你顺利爬坑
- c++中“箭头(->)”和“点号(.)”操作符的区别
- android.content.res.Resources$NotFoundException: String resource ID #0xc
- SSM框架搭建及源码解析--bean的整个生命周期(六)
- CSS选择器
- 自定义JSTL标签库(函数库)
- 安卓接口回调的写法
- Oculus CV1 无法在Steam平台下运行的检测到定位器
- 小功率的串口无线模块的应用
- ios animation动画
- Linux usb子系统(一) _写一个usb鼠标驱动
- 无人驾驶硬件平台
- Android相机开发那些坑
- 关于28377D加密后如何解密烧写程序