[Java EE] El Expressions call Java methods

Source: Internet
Author: User

1. Create a new class, define a static method inside the class

 Package com.tsh.utils; Import Java.net.URLEncoder;  Public class Elfunc {    publicstatic  string UrlEncode (String str) {        return  Urlencoder.encode (str);}    }

2. Create a new TLD under the web-inf folder (except lib and classess directories) file

<?XML version= "1.0" encoding= "UTF-8"?><taglibversion= "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>Elfunc</Short-name>    <URI>Http://www.tsh.com/ELFunc</URI>    <function>        <name>UrlEncode</name>        <Function-class>Com.tsh.utils.ELFunc</Function-class>        <function-signature>Java.lang.String UrlEncode (java.lang.String)</function-signature>    </function></taglib>

3.jsp Head Import

<% @taglib uri= "Http://www.tsh.com/ELFunc" prefix= "Elfunc"%>

4.el Label Use

<%=urlencoder.encode ("Taoshan")%>${elfunc:urlencode ("Taoshan")}
%E9%99%B6%E5%A3%AB%E6%B6%B5%E9%99%B6%E5%A3%AB%E6%B6%B5

manually import jstl using the jstl Tag Library

1. Download the compression pack and put Jstl.jar and standard.jar in Tomcat 's Lib directory under

2. Place the TLD in the web-inf directory

3.jsp page Import <% @taglib uri= "http://java.sun.com/jsp/jstl/functions" prefix= "FN"%>

4. Use ${fn:touppercase ("SDSDSDSSDSDSDSSDDSDSD")}

[Java EE] El Expressions call Java methods

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.