TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag;0 S% n( l) ^# `3 u1 }! S( x1 m i
- ) Y8 o0 r7 Q$ q' F
- import java.io.IOException;! S) |) s. A4 |' S
- import java.text.SimpleDateFormat; q# B+ E1 Y0 Q
- import java.util.Date;! G9 u: q/ w8 w1 X7 F, G
- ' Y# q! |( `- q: J
- import javax.servlet.jsp.JspException;* c/ _$ M. d+ n9 l2 J( `3 O' P
- import javax.servlet.jsp.JspWriter;
( @$ i7 a1 [$ Z7 s, w& G - import javax.servlet.jsp.PageContext;& N8 Z4 M! e4 g M" S
- import javax.servlet.jsp.tagext.SimpleTagSupport;
' e; X4 M, u% X" r# p. n: f6 Y - % X) p3 K! d+ i& A/ {; O( }
- public class DateTag extends SimpleTagSupport{
; B& X% |9 q: |( B7 v - private String quesId;
: W d0 F4 {' l - @Override
6 g8 f8 f4 S0 V1 J - public void doTag() throws JspException, IOException {3 T! j4 p, L( f+ u4 D/ G* r0 l
- String message = "";$ _- [) d: T- P" g( I; w
- if(quesId.equals("0")){
N6 E) w$ k* N0 z# L( Q- | - message = "你好";
9 F+ N: ^3 |3 x6 P - }else{
! L3 g% Q' _% g- k7 | - message = "hello";
8 C q6 q1 z+ A! J8 q - }+ A& p! ~- c# R n) @8 q
- out.println(message);& G$ M3 i+ i/ ]: {. @4 l
- }9 R6 P+ M: @3 \7 X0 l" c1 H
- public String getQuesId() {
, t$ \0 H- @: Q0 Q9 A/ O; F: M% H - return quesId;
: T: e5 w0 l9 H9 _; B( t - }* t8 F8 ?! t! O! s5 Y
- public void setQuesId(String quesId) {8 ?: G7 u5 T# I" c5 I3 F5 T6 O. R
- this.quesId = quesId;& S6 A% n9 p; v4 @. ]
- }) {+ [ P# @1 d A2 W( g+ m
- }
复制代码 标签文件:5 O$ ^; c `8 P% z$ l
- <?xml version="1.0" encoding="UTF-8" ?>
5 x. ^: N; a* [ - <taglib xmlns="http://java.sun.com/xml/ns/j2ee"' q' Z; b2 ~/ W2 g$ r" `6 L
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
) Y5 v; s5 ~/ J' ~ - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
" T- y8 [2 m5 V+ @* W- D8 H - version="2.0">3 O5 O& h% `* j* L: z D( s
- <tlib-version>1.2</tlib-version>0 H% |4 H K' d5 v8 ?
- <short-name>c1</short-name>
. m1 t. X/ Z3 m3 U* U - <uri>http://www.52itstyle.top/mytag</uri>( T c% D' z8 i# J- g9 [0 L
- <tag>: o, w/ R; ?) V* x6 k
- <name>date</name>9 Z9 Q* Y% v: B* L' A7 C
- <tag-class>tag.myTag</tag-class>% t* m$ v) l/ @$ p% e9 b
- <body-content>empty</body-content>2 ^ B0 H9 n# `/ u& L; I
- <attribute> + X% g9 _7 N" o1 N( B$ y
- <name>quesId</name> 9 _5 x( l5 G3 N- I% v& J
- <required>true</required>
. N6 ]& d; _( H& I2 X; z B - <rtexprvalue>true</rtexprvalue>* ^0 [ `! a7 r4 k& C5 g8 f
- </attribute>2 t% F; Q8 l( t! J
- </tag>
& |: p4 _; Z& g - </taglib>
复制代码
0 y: J" N! h1 V0 ~$ M |把以上文件命名mytag.tld 放到WEB-INF 下面 即可 ) x+ ]5 O& ~. G; L. _
===============================
9 C0 w3 P3 V0 S1 \& ?3 E$ b页面加入: o8 V \" x7 r" d
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>- z) w' `5 v7 y) y- i. n4 Y; U* o
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>
$ N& m- }3 m9 ~; n - <c1:date quesId="1"/>
复制代码 ' N, H9 N7 Y; i, ? n9 Y' v
3 e4 e% n% X4 P2 u4 c9 p# G) u" M& g( _
|
|