TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag;7 C. M, b3 i, H- }3 S% h# i
: W0 x2 ?1 k' @- import java.io.IOException;
, k* Z0 a' {8 \% d3 {; d, u3 i. A) e: ^ - import java.text.SimpleDateFormat;7 C @7 \: y) I5 A7 M4 k6 I
- import java.util.Date;# ^( g$ Y# }" p$ p7 w
* g+ y, G, t/ S& l% S- J6 O7 q- import javax.servlet.jsp.JspException;
. I1 f; }0 u4 e4 x - import javax.servlet.jsp.JspWriter;
/ j0 r0 W$ n1 c$ S - import javax.servlet.jsp.PageContext;
$ s9 u7 j$ I% L& x( u1 a9 Y! L3 \ - import javax.servlet.jsp.tagext.SimpleTagSupport;% k/ }# F! H7 Q1 j4 j
$ s/ ~9 `& I" g ?3 [. z- public class DateTag extends SimpleTagSupport{
+ K3 S# B' Z0 X$ H, P) L - private String quesId;! O: B+ G, t+ p" Y+ k3 F* a
- @Override
! ?/ C0 Z9 `6 d- F: J6 c# f - public void doTag() throws JspException, IOException {% C3 i; m8 D% n' t3 J& |2 L4 c
- String message = "";
- u: `6 k$ `: G& X4 a$ v! z% ] - if(quesId.equals("0")){8 V1 u6 j7 D" H
- message = "你好";
- G/ t1 W" S+ o, M& d - }else{
, a' s) e2 t: F- E- p4 |5 { - message = "hello";
- B- I; N/ s$ g0 K - }9 K0 L* y H( b7 @6 h
- out.println(message);2 w+ w1 K# Z: m2 \# W# {9 F
- }1 v' w3 R8 v* V! A; k+ }; o0 O
- public String getQuesId() {& t: ^3 D+ q. H/ V( k
- return quesId;8 @' ~* O5 ]4 k/ w
- }
$ @/ D/ r# \: Y' |% Q2 } ~ - public void setQuesId(String quesId) {
3 ]; h, S# E$ \0 I - this.quesId = quesId;, y4 @* {) z3 X/ |# C+ n' ?
- }
0 f8 q2 U5 l2 D# f+ o! S - }
复制代码 标签文件:
" e/ d f1 V3 F- <?xml version="1.0" encoding="UTF-8" ?>
% m% d- D* Y! s F, s0 f - <taglib xmlns="http://java.sun.com/xml/ns/j2ee". Z2 E$ x( X! q6 |1 y" o
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- X+ B5 N4 ^2 Q, ~2 I5 g - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
& C2 r! l4 I9 e8 [0 k - version="2.0">! T$ W' O# r+ r2 s' J' {
- <tlib-version>1.2</tlib-version>8 X4 Z0 m- q) D( g3 u' q2 |/ q
- <short-name>c1</short-name>; K5 A2 Z% a/ B( N1 i, I2 w
- <uri>http://www.52itstyle.top/mytag</uri>
: i; x5 C( z* w- R# D: C - <tag>9 ~# q8 f, B. p& U: e" R
- <name>date</name>
$ A: [ ^4 {; `: C; D+ p4 m - <tag-class>tag.myTag</tag-class>
; [* M1 F: P- z - <body-content>empty</body-content>
. T! [) Y9 u) s! |; ~2 U; i# O - <attribute> 8 ?. \& p. |9 D! e/ L. n [
- <name>quesId</name> $ r, E9 Y f9 F' N; D8 d. P1 ]% t
- <required>true</required>
, _2 w; I2 r0 v6 [( l R: f" Q1 T - <rtexprvalue>true</rtexprvalue>
( |' l- M5 P* _. b8 `# ~4 b# S9 M - </attribute>
0 \9 M3 S3 d4 g" R - </tag>4 A: N5 M2 T/ \- i( O; o- ]- b6 W
- </taglib>
复制代码 1 x$ Q h% m K$ G( G2 ? @
把以上文件命名mytag.tld 放到WEB-INF 下面 即可
) C+ ]3 f" o$ x8 \ @( R% j$ ~7 k===============================
& V# X* Y) |% J' }* f8 q* ~* O* d页面加入:+ J3 t9 }. I: Z: d
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>& t- V. c& X- K2 ?: v
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>
: H& p9 I/ ?7 S/ d/ ?1 m - <c1:date quesId="1"/>
复制代码 3 T" D# D4 Z3 p, s, k& ]/ q
/ V/ @1 ^( [$ |. W: ]4 z* _
0 e9 {8 {: {- r' g& r |
|