TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag;- w# z, P5 _' m* R4 A# O# b
]4 Z5 @6 t7 V F1 P- import java.io.IOException;' n/ [: w$ t, b6 T
- import java.text.SimpleDateFormat;" v8 [3 q+ @2 P/ ^
- import java.util.Date;. A" |/ H6 B( }7 K
- 4 F# I( |6 ?# t4 W2 W9 R
- import javax.servlet.jsp.JspException;. O4 ]; `! Z2 {, K
- import javax.servlet.jsp.JspWriter;
" G5 F5 |: }9 G: U: \& a u - import javax.servlet.jsp.PageContext;
+ E u0 H! b( Y- v3 }6 @% ] - import javax.servlet.jsp.tagext.SimpleTagSupport;
7 K3 V' ^8 I) }& w9 M+ e" |
3 Z0 v" V N* r) d& x& F! C- public class DateTag extends SimpleTagSupport{5 v8 |( J* ?1 F5 c
- private String quesId;- W+ ]& N- J1 V" M5 P( B
- @Override1 z& K' t% H& ~* {
- public void doTag() throws JspException, IOException {8 e1 G5 U/ F7 d( Y
- String message = "";
. z e* G9 K3 \) m: Q - if(quesId.equals("0")){
5 J# J g1 b* Y% U" X3 M - message = "你好";
. f$ e j+ w; B) X# y - }else{
( l! i3 D8 M9 h - message = "hello";! l3 N7 A9 a+ O: _) X
- }5 G+ r( I7 C* _' P! H
- out.println(message);; z2 ], h) T4 m2 t- A" ~9 m1 _
- }
! K) x: p3 W, d, ^# @( ]/ O - public String getQuesId() {" h5 x0 W) v7 ^3 j4 d/ {& k9 H
- return quesId;( q# W* F; T4 W' Y+ I5 j/ `
- }. D- l) A* v& L% H* i s
- public void setQuesId(String quesId) {
+ M! k8 ~8 @2 A7 Y' |4 n& S B - this.quesId = quesId;
5 N) f9 v( X/ V+ {( V - }
8 U2 @2 d0 i9 F7 I$ [) M - }
复制代码 标签文件:
3 W3 y: f- R! H& _1 m' D; \- <?xml version="1.0" encoding="UTF-8" ?>2 z* N/ }( c3 g3 I+ N
- <taglib xmlns="http://java.sun.com/xml/ns/j2ee"
5 ?' q: w+ o2 e+ F5 @/ [ - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
; o6 a2 @6 {3 P; h6 V2 ^. Z0 g - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
- k; l5 h7 N) u - version="2.0"> S3 k2 O+ G h, M( [0 Q7 z
- <tlib-version>1.2</tlib-version>
1 E e3 j/ w0 j9 ]+ Q; ` - <short-name>c1</short-name>
, s9 S7 M# }2 A* L2 g3 [$ ] - <uri>http://www.52itstyle.top/mytag</uri>
" f" U. C& B9 M2 X7 l0 C+ y! s- } - <tag>! `4 L5 m) G T7 A. v0 G% o e3 C
- <name>date</name>
+ l, W% {; j# H& t+ e" b - <tag-class>tag.myTag</tag-class>
- v- F |0 o! H# k - <body-content>empty</body-content>
8 f" w+ T& z' u. L - <attribute> / I" [/ e( x& S9 u# }
- <name>quesId</name>
8 }; w4 r# Z4 L - <required>true</required>
0 a X$ d6 j9 x( B - <rtexprvalue>true</rtexprvalue>! S/ l8 u' e& K1 a: r3 ?
- </attribute>
# O, C- q6 N$ o5 f+ ]5 n- c7 q, ] - </tag>) `7 h+ }& H) ~- Q6 c
- </taglib>
复制代码
* Z+ @0 g5 B+ [( O9 }, {4 ^/ M3 \) h8 N把以上文件命名mytag.tld 放到WEB-INF 下面 即可 , e4 ]1 c8 X5 Z& [; J) W+ K
===============================, m# H! B1 Y8 q" m
页面加入:
7 y. T$ G2 d& c7 Z6 `' d9 w# M- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>0 Q3 r* y* t' X. G2 Q
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>' F5 H( L8 R9 ]1 f! P1 J) p
- <c1:date quesId="1"/>
复制代码 ) ]6 t; N" e. F! z
3 _- x# e7 v, k6 y1 A
& o" `% ]0 [. a8 x8 z |
|