El expression customization method for front-and-rear interaction TLD

Source: Internet
Author: User
Tags tld

Sometimes when writing a front-end JSP page, you need to get background data, or you want to handle some logic in the background. You can use this method:

1 Background code:

Package com.cd.util;

Import java.util.List;

Get all Provinces
public class Areautil {

private static Icdareaservice Cdareaservice = Springcontextholder.getbean (Icdareaservice.class);
Must be a static method
public static list<area> Getprovincebygrade (int grade) {
return cdareaservice.findprovince (grade);
}

}

2 in the TLD file placed under the Web-inf directory/web-inf/tlds/fns.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>fns</short-name>
<uri>http://java.sun.com/jsp/jstl/functionss</uri>


<!--access to regional provinces-->
<function>
<description> won provinces </description>
<name>getProvinceByGrade</name>
<function-class>com.cd.util.AreaUtil</function-class>
<function-signature>java.util.list Getprovincebygrade (Java.lang.Integer) </function-signature>
<example>${fns:getprovincebygrade (grade)}</example>
</function>

</taglib>

3 introduce a TLD file in a JSP page that needs to use this method:

<%@ taglib prefix= "FNS" uri= "/web-inf/tlds/fns.tld"%>

4 using an EL expression:

<TD style= "Text-align:left;" >
${fns:getprovincebygrade (0)}
</td>


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.