首页 技术 正文
技术 2022年11月16日
0 收藏 886 点赞 2,359 浏览 1573 个字

表达式语言除了可以使用基本的运算符外,还可以使用自定义函数。通过使用自定义函数,加强了表达式语言的功能。

EL表达式函数,主要功能是完成对数据的修改,统一化格式;

步骤

1.开发函数处理类,处理类就是普通的类;每个函数对应类中的一个静态方法;

2. 建立TLD文件,定义表达式函数;

3.在JSP页面内导入并且使用;

1.开发函数处理类

package com.itnba.maya.zidingyi;public class Zidingyi {
public static String zhuanhuan(String txt){
txt=txt.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
txt=txt.replaceAll("/n", "</p><p>");
txt="<p>"+txt+"</p>";
return txt;
}}

2.创建配置TLD文件

创建在WEB-INF文件夹里面

EL表达式自定义函数

配置

<?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>自定义函数</description>
<display-name>我的el function</display-name>
<tlib-version>1.0</tlib-version>
<short-name>fn</short-name>
<uri>http://www.itnba.com</uri> <function>
<description>
把文本的显示内容改成网页的显示内容
</description>
<name>zhuanhuan</name>
<function-class>com.itnba.maya.zidingyi.Zidingyi</function-class>
<function-signature>String zhuanhuan(java.lang.String)</function-signature>
<example>
...
</example>
</function>
</taglib>

3.在JSP页面内导入并且使用

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="my" uri="http://www.itnba.com" %> <%--调用 --%> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>aa</h1>
${my:zhuanhuan("<h1>aa</h1>") }</body>
</html>

显示结果

EL表达式自定义函数

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,903
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,428
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,245
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,057
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,689
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,726