TA的每日心情 | 衰 2021-2-2 11:21 |
---|
签到天数: 36 天 [LV.5]常住居民I
|
- package mytag.tag;2 h" k6 s. Z4 T5 W: _5 e6 y
6 {2 V- M) p9 @! K0 K; x- import java.io.IOException;
3 F5 V; [) f; W5 n6 n/ W, V# d! r - import java.text.SimpleDateFormat;
, X+ U! P( c9 j3 }4 H; W3 M4 y - import java.util.Date;
0 f. q5 O7 M* O - # @% X; ]5 d0 I& r: l5 Y
- import javax.servlet.jsp.JspException;
) q# S! C; b5 o7 P# }0 M6 K* P. d+ V - import javax.servlet.jsp.JspWriter;% C8 `8 t6 M3 d# a. D; {! Z! g
- import javax.servlet.jsp.PageContext;
' N2 J- y5 o7 a2 A4 x* {% | - import javax.servlet.jsp.tagext.SimpleTagSupport;
4 q3 R8 w5 G; c3 C
+ j/ [/ ^, j' U; c6 z2 u* p3 l5 i- public class DateTag extends SimpleTagSupport{
5 E7 F- E: m" w4 I+ f- T/ c7 @ - private String quesId;8 d L7 s9 _ ?+ s9 E
- @Override) o* w1 X+ `& j' `9 e! a$ r
- public void doTag() throws JspException, IOException {
/ E( R) i4 [% r - String message = "";; _7 G: _ d5 e! A4 C$ N
- if(quesId.equals("0")){
8 }! C4 l2 @8 t9 A - message = "你好";
/ p! X" M# J7 t' c$ @ - }else{
0 C! Y$ {9 e2 u2 J3 q9 m8 N* { - message = "hello";& m9 Y0 m U3 n
- }1 {; z' q0 T/ w: g
- out.println(message);9 u* T* @( D2 x) m% h5 n+ Y' E
- }: G1 b( j. i0 E- B7 p
- public String getQuesId() {; h# U3 w% i% y& @/ i, g) R
- return quesId;
- e d, z x2 @ - }8 Y4 W: t9 l6 Q4 G! C
- public void setQuesId(String quesId) {3 A/ k- n( O' L6 h( _: P" @
- this.quesId = quesId;
3 P( ^7 O2 t8 M$ S$ O/ H$ X - }, T0 |! t& O" p. J$ u4 H) X
- }
复制代码 标签文件:
' V1 Z% K/ Z" `1 K; d+ U5 B w- <?xml version="1.0" encoding="UTF-8" ?>1 p2 \% K5 u: I0 `4 f8 V
- <taglib xmlns="http://java.sun.com/xml/ns/j2ee"% K+ S" s* u" S- s
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
) {, W5 q& _) Z; i# X6 J2 u# m - xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"3 s: F+ v8 T, E9 ~# U0 ]" J6 P
- version="2.0">; s3 x' X2 b4 w# k) a# z
- <tlib-version>1.2</tlib-version>
# G5 F4 u5 x" N, e8 |3 X - <short-name>c1</short-name>
- R6 Z) |) D" K$ ] - <uri>http://www.52itstyle.top/mytag</uri>
5 Y6 K6 x( S0 ]0 X/ X7 l! e - <tag>7 ?4 U T3 G0 g
- <name>date</name>& d) }' Y0 m- U) v
- <tag-class>tag.myTag</tag-class>
, C6 t6 U8 y4 _7 H8 | - <body-content>empty</body-content>
& s4 Z5 w9 I& G; M - <attribute>
8 J j" D5 g5 Q8 S; P - <name>quesId</name> 9 b, X. }; x- I; g0 Y) R
- <required>true</required> 6 H' k6 _+ Q* j& O& {
- <rtexprvalue>true</rtexprvalue>
4 R9 r! l4 q" o$ f - </attribute>+ n( _2 ]# D" m& c0 ?& U5 w# s5 y5 _
- </tag>" ?' `8 W5 Z" A
- </taglib>
复制代码 4 R* m: t3 h B- W# m3 S' y
把以上文件命名mytag.tld 放到WEB-INF 下面 即可 ! m! w$ F5 N7 A
===============================
3 Y" o+ k. V- j% d( F$ ?$ q5 M" j页面加入:% v- W& _8 `( l
- <%@ page language="java" import="java.util.*" pageEncoding="utf-8" isELIgnored="false"%>0 j5 @8 l( R+ [7 J
- <%@taglib uri="/WEB-INF/mytag.tld" prefix="c1"%>
" F3 U! A( f3 H; f( D2 A. f - <c1:date quesId="1"/>
复制代码 ; r6 `! s4 u( L7 G
$ C& b# R) N, X# w9 p- u2 r' m. \
. r, ~2 s5 G, G5 u |
|