码迷,mamicode.com
首页 > 系统相关 > 详细

eclipse新建自定义EL函数

时间:2016-08-09 00:03:50      阅读:287      评论:0      收藏:0      [点我收藏+]

标签:

===============================================================================================================================

step1:新建一个java类

这个类有一点需要注意,方法必须是静态的. 这个也好理解,EL调用的函数,可以算是一个工具类,没有必要先实例化再调用. 最理想的方法就是整成静态方法,直接通过类来调用就可以了.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

package net.thecatcher.ELdemo;

public class ELDemo1 {

public static String sayHello(String name){

return "hello "+ name;

       }

}

===============================================================================================================================

step2: 需要编辑的tld文件

我用的eclipse,查到的方法是这样来建,但是,貌似不太好使. 我都是直接复制下面这段代码,然后再修改...

New ----> XML ----> XML File ----> 输入test.tld
----> Create XML file from a DTD file ----> Select XML Catalog entry
----> -//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN 
----> finish

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

<?xmlversion="1.0"encoding="UTF-8"?>

<taglib version="2.0" 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">

<tlib-version>1.0</tlib-version>

<short-name>myfn</short-name>

<uri>http://www.thecatcher/myfn</uri>

<function>

<name>sayHi</name>

<function-class>net.thecatcher.ELdemo.ELDemo1</function-class>

<function-signature>java.lang.String sayHello(java.lang.String)</function-signature>

</function>

</taglib>

===============================================================================================================================

step3: jsp文件中通过taglib引用

-------------------------------------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ taglib uri="http://www.thecatcher/myfn" prefix="myfn" %>

<!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=UTF-8">

<title>Insert title here</title>

</head>

<body>

${ myfn:sayHi("meimei")}

</body>

</html>

eclipse新建自定义EL函数

标签:

原文地址:http://www.cnblogs.com/thecatcher/p/5751409.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!