TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag;
8 G+ A9 Y# @3 P, I
2 |/ J: g4 g8 j" S* h& d- A" @- import java.io.IOException;" X: z# x# I5 w0 A6 ]- Z0 Y6 f) I+ _7 V
- import java.text.SimpleDateFormat;
* W8 o( y. l1 }8 v0 L0 j# A# p - import java.util.Date;
$ c3 G) u4 T+ H
+ S) Z6 @3 k4 _$ V- ]9 P( f- import javax.servlet.jsp.JspException;( W+ m0 `% z$ Y! J6 K# R' Y: y
- import javax.servlet.jsp.JspWriter;
+ ^0 B- ?- X) @ K9 n# f/ ^ - import javax.servlet.jsp.PageContext;
& i t- _: G( _9 ~" s, k. z. A; ` - import javax.servlet.jsp.tagext.SimpleTagSupport;3 F! I5 f! |' A
- # _4 A& t, V; a; Z
- public class DateTag extends SimpleTagSupport{
V( h1 Y" L. T; v - private String quesId;, T8 q* _" n8 Y5 K; }) ] V
- @Override
" k7 B' y( g1 y# g7 m - public void doTag() throws JspException, IOException {
3 y- I1 @2 M: ^/ h - String message = "";
: `/ u" P2 m! ^$ v - if(quesId.equals("0")){+ U# i) i: D# p) F2 u% ]+ M2 f
- message = "你好";
; ~/ F3 t {) i; L* D" c - }else{
+ A7 S" r( N( H - message = "hello";6 N* A4 n' A5 t$ B; o" f
- }
( U3 v: T* Y" t7 f2 q - out.println(message);* p9 v/ A0 i$ }& {1 L
- }
& r- w+ x/ A1 p% v) F% i0 V/ p# `7 k - public String getQuesId() {
C8 Q6 \7 m. D, G2 }6 U - return quesId;
! N1 V1 g0 ~, G0 [: B - }' f( n* C9 t- u$ ~: Z2 c, d9 f+ ~
- public void setQuesId(String quesId) {5 e7 K4 Y! T9 o# {/ j0 P% j
- this.quesId = quesId;
8 T3 A% G+ w" |7 C9 B - }/ }+ t2 {2 c7 _% b( M
- }
复制代码 标签文件:2 @+ A0 ^ j' _' Y2 N; C
- <?xml version="1.0" encoding="UTF-8" ?>
" `% O' X* h% U4 \ - <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
# _6 _4 ^8 w* h# [9 V. b, L6 p - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"( W( S& h( |; }0 p* R: v7 l' j
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
( M: I- e! P. n3 J5 v+ F - version="2.0">- E3 F: L& C0 `& V e( L/ l
- <tlib-version>1.2</tlib-version>
% T, G% I( F9 l+ Z: Y - <short-name>c1</short-name>5 I! T& Y/ |8 C! u3 a6 |: d
- <uri>http://www.52itstyle.top/mytag</uri>
$ l* {/ H' g+ m7 S% L7 a - <tag>
2 N7 Q7 G4 r" Q! W3 t& W - <name>date</name>9 t% L' a! Q1 S; T! `. G
- <tag-class>tag.myTag</tag-class>2 d' _& |% f# l; j% ^1 o0 ]1 T& L. t
- <body-content>empty</body-content>
8 h, N- U5 A/ \# I - <attribute> - p- Z9 U; h6 a9 x
- <name>quesId</name> # s1 T$ @9 T/ _3 F
- <required>true</required> 4 Q4 k q+ Z) r
- <rtexprvalue>true</rtexprvalue>: |7 x# Y1 g3 u% Z$ x) G; q
- </attribute>
* [% R0 F) z1 K3 u6 E) ^ - </tag>
5 P- u" B8 p$ O6 X$ H, F A - </taglib>
复制代码
7 K$ `4 S; s! I8 ?) Y8 W把以上文件命名mytag.tld 放到WEB-INF 下面 即可
2 Q8 J! E4 W+ A+ y y% j; h5 n' }===============================
$ W2 f3 E2 \! J页面加入:( _5 {3 Z! B7 n0 k: a* o
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>6 x% D) c+ @" ?4 z; H; r
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>! \0 `7 U% Q6 g; v" }6 ?
- <c1:date quesId="1"/>
复制代码
v+ Z+ e% |' d! b
* K$ C3 g' Z7 p9 N
. A9 c3 v: o9 O |
|