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>