jstl自定义标签
2011-05-19 19:22
302 查看
jstl标签可以 方便页面的调用,通过直接访问页面就可以调用函数返回数据并进行页面显示
1、新建后台调用的java类:
package com.jrcz.aura.util;
import java.util.List;
import org.springframework.stereotype.Component;
import com.jrcz.aura.model.Employee;
import com.jrcz.aura.service.EmployeeManager;
@Component
public class EmployeeFunction {
private static EmployeeManager employeeManager;
public static List<Employee> getEmp(){
int deptid = 1;
List<Employee> list = null;
// List<Employee> list = employeeManager.getEmpByDeptID(deptid);
// System.out.println("list:"+list.size());
System.out.println("jstl测试");
return list;
}
public static void setEmployeeManager(EmployeeManager employeeManager) {
EmployeeFunction.employeeManager = employeeManager;
}
}
2、写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">
<tlib-version>1.0</tlib-version>
<short-name>gpb_jstl</short-name>
<uri>http://www.jrcz.com/gpb_jstl/functions</uri>
<function>
<name>getEmp</name>
<function-class>com.jrcz.aura.util.EmployeeFunction</function-class>
<function-signature>java.util.List getEmp()</function-signature>
</function>
</taglib>
3、在web.xml文件中配置:
<!-- 配置jstl标签 -->
<jsp-config>
<taglib>
<taglib-uri>http://www.jrcz.com/gpb_jstl/functions</taglib-uri>
<taglib-location>/WEB-INF/gpb_jstl.tld</taglib-location>
</taglib>
</jsp-config>
4、jsp页面调用:
在页面头部引用
<%@ taglib uri="http://www.jrcz.com/gpb_jstl/functions" prefix="gpb_jstl" %>
页面显示层
<c:forEach items="${gpb_jstl:getEmp()}" var="model" varStatus="st">
<tr valign="middle" <c:if test="${st.index % 2 != 0}">bgcolor="#e6f7fe"</c:if><c:if test="${st.index % 2 == 0}">bgcolor="#f7fcff"</c:if>>
<td align="center"><input type="checkbox" name="items" value="empid=${model.empid}&" id="items" /></td>
<td >${model.empid}</td>
<td >${model.ename}</td>
<td >${model.salary}</td>
<td >${model.dept.dname}</td>
<td >${model.location}</td>
</tr>
</c:forEach>
1、新建后台调用的java类:
package com.jrcz.aura.util;
import java.util.List;
import org.springframework.stereotype.Component;
import com.jrcz.aura.model.Employee;
import com.jrcz.aura.service.EmployeeManager;
@Component
public class EmployeeFunction {
private static EmployeeManager employeeManager;
public static List<Employee> getEmp(){
int deptid = 1;
List<Employee> list = null;
// List<Employee> list = employeeManager.getEmpByDeptID(deptid);
// System.out.println("list:"+list.size());
System.out.println("jstl测试");
return list;
}
public static void setEmployeeManager(EmployeeManager employeeManager) {
EmployeeFunction.employeeManager = employeeManager;
}
}
2、写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">
<tlib-version>1.0</tlib-version>
<short-name>gpb_jstl</short-name>
<uri>http://www.jrcz.com/gpb_jstl/functions</uri>
<function>
<name>getEmp</name>
<function-class>com.jrcz.aura.util.EmployeeFunction</function-class>
<function-signature>java.util.List getEmp()</function-signature>
</function>
</taglib>
3、在web.xml文件中配置:
<!-- 配置jstl标签 -->
<jsp-config>
<taglib>
<taglib-uri>http://www.jrcz.com/gpb_jstl/functions</taglib-uri>
<taglib-location>/WEB-INF/gpb_jstl.tld</taglib-location>
</taglib>
</jsp-config>
4、jsp页面调用:
在页面头部引用
<%@ taglib uri="http://www.jrcz.com/gpb_jstl/functions" prefix="gpb_jstl" %>
页面显示层
<c:forEach items="${gpb_jstl:getEmp()}" var="model" varStatus="st">
<tr valign="middle" <c:if test="${st.index % 2 != 0}">bgcolor="#e6f7fe"</c:if><c:if test="${st.index % 2 == 0}">bgcolor="#f7fcff"</c:if>>
<td align="center"><input type="checkbox" name="items" value="empid=${model.empid}&" id="items" /></td>
<td >${model.empid}</td>
<td >${model.ename}</td>
<td >${model.salary}</td>
<td >${model.dept.dname}</td>
<td >${model.location}</td>
</tr>
</c:forEach>
相关文章推荐
- IT忍者神龟之jsp标签、EL表达式、JSTL标签、函数、自定义标签
- Java Web基础——自定义标签和JSTL
- 分页插件开发(1)--jstl自定义标签
- 黑马总结: jstl自定义标签
- JSTL自定义标签的使用
- JSTL自定义标签二SimpleTagSupport(一)
- 18、EL表达式、JSP标签、JSTL标签、自定义标签
- JSTL_自定义标签
- JSTL自定义标签
- 自定义标签(JSTL)
- JSTL标签库,自定义标签
- EL表达式、JSP标签、JSTL标签、自定义标签
- 十六、初学jsp之jstl标签与自定义标签
- jstl自定义标签防盗链
- JSP自定义标签(2)JSTL标签库
- JSTL自定义标签
- Java Web基础——自定义标签和JSTL
- JSTL自定义标签
- 使用自定义标签模拟jstl的<c:for each>标签
- 自定义标签jstl