jstl自定义标签

1、引入jstl.jar

<!-- JSTL标签类 -->
		<dependency>
			<groupId>jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>

2、自定义标签处理类

package com.loan.security.web.taglib;

import java.util.List;

import org.springframework.web.bind.annotation.ResponseBody;

import com.loan.security.entity.Dictionary;
import com.loan.security.service.DictionaryService;
import com.loan.security.spring.SpringUtils;
public class DictionaryFunction {
	private static DictionaryService dictionaryService;
	
	public static @ResponseBody List<Dictionary> getDictionarysByCode(String code) {
		Dictionary dic=new Dictionary();
		dic.setCode(code);
		return getDictionaryService().find(dic);
	}
	public static DictionaryService getDictionaryService() {
		if(dictionaryService == null) {
			dictionaryService = SpringUtils.getBean(DictionaryService.class);
		}
		return dictionaryService;
	}
}

3、标签库描述文件(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>functions</description>
    <tlib-version>3.0</tlib-version>
    <short-name>fn</short-name>
    <function>
        <description>根据code查询字典列表</description>
        <name>getDictionarysByCode</name>
        <function-class>com.loan.security.web.taglib.DictionaryFunction</function-class>
        <function-signature>java.util.List getDictionarysByCode(java.lang.String)</function-signature>
    </function>

</taglib>
4、jsp中引入并使用自定义标签

<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="dictionary"
	uri="/WEB-INF/tld/dictionary_function.tld"%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title></title>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/static/common/easy-ui/js/jquery.min.js"></script>
</head>
<body style="margin: 0px; padding: 0px; height: 100%; font-family: 微软雅黑;">
	<div style="padding: 10px;">
		<label style="width: 15%">类型:</label> 
		<select style="width: 30%" name="type" class="easyui-combobox" required="true">
			<c:forEach items="${dictionary:getDictionarysByCode('0003')}" var="dic">
				<option value="${dic.name}">${dic.name}</option>
			</c:forEach>
		</select> 
	</div>
</body>
</html>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值