<%@taglibur" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

JavaWeb 自定義 “標(biāo)簽文件” 而非 "標(biāo)簽"

系統(tǒng) 2583 0
目標(biāo)
1.創(chuàng)建 自定義 標(biāo)簽文件 : 在 WEB-INF/tags/ 定義一個(gè)后綴名為 .tag 的文件 然后在jsp頁面引用.

2.自己寫的一些小例子,在附件中【包含:自定義標(biāo)簽,自定義標(biāo)簽文件,打包標(biāo)簽文件,分頁標(biāo)簽,錢大寫,dataGridView 等】

STEP:1 ? --dataGridViewTagFile.tag
    <%@ tag body-content="scriptless" pageEncoding="UTF-8" %>
<!-- 【引用JSTL標(biāo)簽】-->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!-- 【必須屬性】 在標(biāo)簽文件中定義屬性dataScource:數(shù)據(jù)源 -->
<%@ attribute name="dataSource" required="true" type="javax.servlet.jsp.jstl.sql.Result"%>
<!-- 【可選參數(shù)】 自定義 要顯示的列名 采用“,”分割 ,default:所有列-->
<%@ attribute name="colunms" type="java.lang.String"%>
<!-- 【可選參數(shù)】  table表單的id值  -->
<%@ attribute name="id" type="java.lang.String"%>
<!-- 【可選參數(shù)】 table表單的class -->
<%@ attribute name="cls" type="java.lang.String"%>
<!-- 【可選參數(shù)】 奇數(shù)tr的class -->
<%@ attribute name="otrcls" type="java.lang.String"%>
<!-- 【可選參數(shù)】偶數(shù)tr的class -->
<%@ attribute name="etrcls" type="java.lang.String"%>


<!-- 編寫表單 -->
<table border="1" id="${id}" class="${cls}">
	<tr bgcolor="#CCCCCC">
		<!-- 顯示 表頭列名 -->
		<c:choose>
			<c:when test="${colunms ne null && fn:length(colunms) gt 0}">
				<c:forEach var="columnName" items="${fn:split(colunms,',')}">
					<c:if test="${fn:length(columnName) gt 0}">
						<th>${columnName}</th>
					</c:if>
				</c:forEach>
			</c:when>
			<c:otherwise>
				<c:forEach items="${dataSource.columnNames}" var="columnName">
					<th>${columnName}</th>
				</c:forEach>
			</c:otherwise>
		</c:choose>
	</tr>
	<!-- 顯示 表中數(shù)據(jù) -->
	<c:forEach items="${dataSource.rows}" var="row" varStatus="varIndex">
		<!-- 控制奇偶樣式 -->
		<c:if test="${varIndex.index mod 2 eq 0}">
			<tr class="${otrcls}">
		</c:if>
		<c:if test="${varIndex.index mod 2 ne 0}">
			<tr class="${etrcls}">
		</c:if>
		<!-- 顯示數(shù)據(jù) -->
		<c:choose>
			<c:when test="${colunms ne null && fn:length(colunms) gt 0}">
				<c:forEach var="columnName" items="${fn:split(colunms,',')}">
					<c:if test="${fn:length(columnName) gt 0}">
						<td>${row[columnName]}</td>
					</c:if>
				</c:forEach>
			</c:when>
			<c:otherwise>
				<c:forEach var="columnName" items="${dataSource.columnNames}">
					<td>${row[columnName]}</td>
				</c:forEach>
			</c:otherwise>
		</c:choose>
		</tr>
	</c:forEach>
</table>

  

STEP:2 ? --在index.jsp中引用標(biāo)簽文件并利用
    <%@ page language="java" import="java.util.*"
	pageEncoding="UTF-8"%>
<!-- jsp:directive.page:只在當(dāng)前頁面 能夠訪問  jsp:include 的頁面不能使用  和 import 都可以使用訪問  -->
<jsp:directive.page import="javax.servlet.jsp.jstl.sql.Result" />
<jsp:directive.page import="com.soft.common.*" />
<!--引用自定義標(biāo)簽文件中的表  -->
<%@ taglib tagdir="/WEB-INF/tags" prefix="javaweb"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style type="text/css">
#customers
  {
  font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
  border-collapse:collapse;
  }

#customers td, #customers th 
  {
  font-size:1em;
  border:1px solid #98bf21;
  padding:3px 7px 2px 7px;
  }

#customers th 
  {
  font-size:1.1em;
  text-align:left;
  padding-top:5px;
  padding-bottom:4px;
  background-color:#A7C942;
  color:#ffffff;
  }
#customers tr.alt td 
  {
  color:#000000;
  background-color:#EAF2D3;
  }
</style>
</head>
<body>
		<%
			//獲取數(shù)據(jù)源
			Result result = BaseDAO.runSelectSql("select id,loginname,sex,password from bi_user where rownum<15");
			pageContext.setAttribute("dataSource", result);
		%>
定義DataGridView標(biāo)簽 顯示部分列名
		<javaweb:gridViewTagFile dataSource="${dataSource}" id="customers" etrcls="alt" colunms="id,loginname,SEX,PASSWORD"/>
</body>
</html>

  

STEP:3 ? --效果圖

JavaWeb 自定義 “標(biāo)簽文件” 而非 "標(biāo)簽"

JavaWeb 自定義 “標(biāo)簽文件” 而非 "標(biāo)簽"


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 建昌县| 色达县| 古交市| 万源市| 磐石市| 浦东新区| 抚松县| 陆丰市| 中山市| 博湖县| 云龙县| 永泰县| 富顺县| 芦溪县| 蒙自县| 永嘉县| 张家界市| 金堂县| 平乡县| 东莞市| 鄂托克前旗| 郎溪县| 洪雅县| 夹江县| 句容市| 孙吴县| 泰和县| 德昌县| 濮阳市| 红原县| 建水县| 铁岭市| 屏东市| 洞口县| 夹江县| 丰都县| 惠东县| 大足县| 自贡市| 来安县| 吉林省|