El expression Call function __ function

Source: Internet
Author: User
Tags tld

First, let's talk about how OGNL calls.

<s:setname= "albumimg" value= "@com. ISS.PORTAL.BASE.UTIL.FILETOOLS@GETIMGBYWH (#oneAlbum. Cover, ' 100x100 ')" > </s:set>

Secondly

El expressions invoke Custom functions

The function in the 1 El expression call JavaBean is very simple, as long as there is a getxxx method, you can write ${javaben.xxx on the page to invoke the method

2 El expression calls the method in the label <tag>:

as in El Call Jstl, the <fn:contains/> method is as follows: \

<%@ taglib prefix= "FN" uri= "http://java.sun.com/jsp/jstl/functions"%> ${fn:contains

(STRINGA,STRINGB)}


Additionally El calls the custom label method as follows:

1. Create a mytag.tld file under the Webroot\web-inf directory.

2.mytag.tld content is

<?xml version= "1.0" encoding= "UTF-8"?> <taglib "xmlns=" 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 "> <tlib-version>1.0</tlib-versio N> <short-name>el</short-name> <function> <!--description of this El method--> <description 

        >calculate string length</description> <name>FunctionsEl</name><!--Call the name of the El method--> 

             <function-class>com.el.code.FunctionsEl</function-class> <function-signature> Java.lang.String Elencode (java.lang.String) </function-signature> <example>${el:funct Ionsel (str)}</example><!--For example--> </function> </taglib> 

3. Under the Com.el.code package, create a new class named Functionsel.

Package com.gouwu.youboy.util;

 

Import java.io.UnsupportedEncodingException;

Import Java.net.URLEncoder;

 

/**

 * @project XXX *

 @author: XXX

 * @version 1.0

 * @Create: 5:41:27 PM

 * @Update:

 * @describe : * * Public

class Functionsel {

    /**

     * transcoding in Chinese

     * @param str Chinese string

     * @return A string after Chinese encoding

     *

    /public static string Elencode (String str) {

        string decodestr = null;

        try {

            decodestr = Urlencoder.encode (str, "UTF-8");

        } catch (Unsupportedencodingexception e) {

            E.printstacktrace ();

        }

        Return Decodestr

    }

 

}


4. Refer to the JSP page as follows:

<%@ taglib prefix= "el" uri= "/web-inf/mytag.tld"%>

${el:functionsel (iklist)}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.