TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag; c2 L1 F' {' U( b; p3 \- r
- % _, Y3 i! k7 A/ Z, J1 j
- import java.io.IOException;' F5 F* S1 |: o6 {9 _
- import java.text.SimpleDateFormat;
9 k+ O9 [, U6 w - import java.util.Date;# P* e7 z8 k' `9 x S1 i, ?4 R
: b- w: F" I% H, `' x- import javax.servlet.jsp.JspException;7 S4 j# n% a$ c, |
- import javax.servlet.jsp.JspWriter;
5 ~7 f8 g! B" e3 c1 C _ - import javax.servlet.jsp.PageContext;$ B1 F0 w/ Z& x/ I. o8 @% ^
- import javax.servlet.jsp.tagext.SimpleTagSupport;2 R" y0 l5 i! E/ `9 F; L
{9 M% j$ |3 k/ c7 I- public class DateTag extends SimpleTagSupport{ T* y$ T, r3 t5 |" Y' {
- private String quesId;$ K9 o0 n3 E: p/ }( L
- @Override+ F" ^0 q+ r* X6 j6 z. b
- public void doTag() throws JspException, IOException {
+ z$ v; l( D+ ^" e - String message = "";
6 v+ O- L6 r6 ? - if(quesId.equals("0")){
" p D# y$ O1 w& H' Q; p - message = "你好";0 N" N5 g$ d8 Q3 }$ m
- }else{
9 E$ d/ ~# ~ K. ^& { - message = "hello";( s' A3 c/ P7 K, Y% Z- t
- }
/ a; d& Z' R% I" A! I6 p- E! Z - out.println(message);
, w- K | R; G/ A7 W' ] - }) r; R# N2 y2 t5 p8 l
- public String getQuesId() {
% [+ B# V" C1 ?) A - return quesId;. _, g# k* E1 j
- } R! F5 A2 H2 s
- public void setQuesId(String quesId) {4 l1 r- z! n$ G( f( b& H. D2 \
- this.quesId = quesId;; d9 i% l0 Y5 o
- }
/ u6 Q. M x$ t$ }+ u k: e6 m: @/ S - }
复制代码 标签文件:
M* M: x% j! y7 q @/ x! S- <?xml version="1.0" encoding="UTF-8" ?>/ ~7 m4 V6 p/ e! d6 u
- <taglib xmlns="http://java.sun.com/xml/ns/j2ee": C. e1 n4 Y: V8 |5 v! \
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
E, w0 G, z* P- F7 }9 z' f4 W - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd", D: k6 e. J& k1 b7 a5 a
- version="2.0">
8 R6 {( y2 v+ B" y! x - <tlib-version>1.2</tlib-version>
# U# F5 d1 V4 U. @ - <short-name>c1</short-name>, L* B* q& i7 G! |' u1 J
- <uri>http://www.52itstyle.top/mytag</uri>/ }! |% T: S+ V8 W8 ~; }( o6 q! Z
- <tag>
# G* r, O5 y1 o - <name>date</name>
" @! d, h; k* u8 h/ _1 _ - <tag-class>tag.myTag</tag-class>
! c* G0 J- i, P4 L7 d - <body-content>empty</body-content>
* F. \) x4 h* a8 R' q9 Z - <attribute>
3 m' M* G5 w9 B d - <name>quesId</name>
6 R2 F5 \/ B: f( C+ c - <required>true</required> 9 R( p) s9 `9 j4 |- @7 I- Q m6 A
- <rtexprvalue>true</rtexprvalue>
9 ^$ Y b. G6 L7 }9 D, K. |) L - </attribute>
3 F. W0 c2 C6 C# m - </tag>
% o1 m' ?: x: Z" k0 H4 E - </taglib>
复制代码
# v+ Y6 R$ V% ?) m) i; w& ^, Q把以上文件命名mytag.tld 放到WEB-INF 下面 即可 : n% m* K3 Y N$ _( f2 ]
===============================9 W2 S, W' [4 k; m2 t6 {1 Z
页面加入:
; L# V" R1 H" K6 a9 L# T5 M- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>: Y( s& d# o U4 {) s! n) p
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>; ~4 y, `6 b- Z- V
- <c1:date quesId="1"/>
复制代码
6 U, d8 f, {: ^' p% \
* f, h" m6 l& B: a3 ]
^4 c& R1 I1 \7 Z: P& a |
|