1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package examples;
18
19 import java.io.IOException;
20
21 import javax.servlet.jsp.JspException;
22 import javax.servlet.jsp.JspTagException;
23
24
25
26
27
28
29
30
31 public class FooTag
32 extends ExampleTagBase {
33 private String atts[] = new String[3];
34 int i = 0;
35
36 private final void setAtt(int index, String value) {
37 atts[index] = value;
38 }
39
40 public void setAtt1(String value) {
41 setAtt(0, value);
42 }
43
44 public void setAtt2(String value) {
45 setAtt(1, value);
46 }
47
48 public void setAtt3(String value) {
49 setAtt(2, value);
50 }
51
52
53
54
55
56
57 public int doStartTag() throws JspException {
58 i = 0;
59 return EVAL_BODY_TAG;
60 }
61
62 public void doInitBody() throws JspException {
63 pageContext.setAttribute("member", atts[i]);
64 i++;
65 }
66
67 public int doAfterBody() throws JspException {
68 try {
69 if (i == 3) {
70 bodyOut.writeOut(bodyOut.getEnclosingWriter());
71 return SKIP_BODY;
72 } else
73 pageContext.setAttribute("member", atts[i]);
74 i++;
75 return EVAL_BODY_TAG;
76 } catch (IOException ex) {
77 throw new JspTagException(ex.toString());
78 }
79 }
80 }
81