TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag;2 w% J- C# J' i' t- o
- 8 Y# u+ B4 M: \- w- L1 X
- import java.io.IOException;
; D/ i% I3 u- Z9 j - import java.text.SimpleDateFormat;
9 g. F' a( A) D6 m+ [ - import java.util.Date;! Y" q m) i; ~, W, A* o4 ?
& z/ \/ a" ]. H! P4 ?7 L- import javax.servlet.jsp.JspException;
& |6 d2 q' T% ]& Z6 `2 t5 i& M - import javax.servlet.jsp.JspWriter;9 F! @# Q% J2 q" w. I8 T
- import javax.servlet.jsp.PageContext;0 U" R& _0 a; x; {3 y2 n
- import javax.servlet.jsp.tagext.SimpleTagSupport;5 ^' |# L# ~" l9 d- t. ~
- % j. j3 O( n1 r' T1 P) l
- public class DateTag extends SimpleTagSupport{3 n# }: ]' v4 K( T& X0 ~
- private String quesId;. S) |& R- E& D2 p* x# q
- @Override
3 K% b1 v* L& D - public void doTag() throws JspException, IOException { A' u3 n# o+ e; S/ e. u% T$ ^3 L
- String message = "";
* P/ w- c) \9 T5 d) U1 n - if(quesId.equals("0")){& d: b6 s! e* c2 ^/ {- Y% I4 h1 f
- message = "你好";+ n1 w/ O) ?7 @* e
- }else{3 E/ _1 ]3 `5 \9 \4 t9 [
- message = "hello";
/ w9 U$ g3 ]3 w& d* c - }8 X M/ q) I. D
- out.println(message);
" w5 r8 a5 l3 y& Z8 K8 {7 |4 | - }6 S( F3 K5 ~3 P# Y) V
- public String getQuesId() {/ _9 X: q7 T, j& I: z5 B
- return quesId;6 ~0 G# i9 V3 M" }/ ]5 Q9 t7 Z
- }% L2 |6 l% @8 ^6 k0 Z0 `
- public void setQuesId(String quesId) {
. X, N: r& t8 D+ n% | - this.quesId = quesId;
0 ~- q9 r4 N7 [5 g2 s - }
9 j1 s" c5 p7 j - }
复制代码 标签文件:! x2 T( \) B w: D. y) A
- <?xml version="1.0" encoding="UTF-8" ?>
* x7 D( N7 w" ^6 k5 T7 g4 J& a - <taglib xmlns="http://java.sun.com/xml/ns/j2ee"2 G" d8 ]0 B* e7 u3 E0 f( j6 N
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"6 d, M: U: {7 O6 O
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
7 n) l8 R; G6 K6 k - version="2.0">& n+ E+ d' D( \, M6 `* I$ `
- <tlib-version>1.2</tlib-version>
" K9 T3 q- K# ~0 R - <short-name>c1</short-name>2 O L7 u- s* Y$ ]3 Q7 u
- <uri>http://www.52itstyle.top/mytag</uri>: b! l" a+ G2 ]. ]2 \
- <tag>
/ z8 V- l, _# k! } - <name>date</name>! V$ ~+ P) X% d& H. A6 a% F
- <tag-class>tag.myTag</tag-class>
8 H8 ` l6 A8 h: e& t; i" G - <body-content>empty</body-content>
& A1 I: D" [3 ^1 W& s/ |( N - <attribute> - O* l( {9 b* W/ t( L+ l5 v
- <name>quesId</name> / O1 O7 ^1 ?8 j5 C, R# o$ m$ e
- <required>true</required> 7 Y0 R3 a7 j, e8 ~
- <rtexprvalue>true</rtexprvalue>
0 X) j g5 B% \% i - </attribute>, p% |6 }2 `& p# x0 f/ S! Y
- </tag>
8 t5 x, Z0 a1 i - </taglib>
复制代码
5 ]2 |2 Q& r. }; e把以上文件命名mytag.tld 放到WEB-INF 下面 即可
9 H) C0 T+ X' B/ I. P% `% c9 |8 J===============================* a3 Z' Z0 u' R4 h: i6 C
页面加入:
7 P% [. a3 B6 J- s7 M, q _- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>% r% j8 U U6 V! i6 y* m$ @
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>8 h r& F t- Y" ?
- <c1:date quesId="1"/>
复制代码 8 b% N& O; o6 C& o" |+ S/ g
$ B' m0 _) H: |6 v+ Y) D4 \! w- W6 d8 v
|
|