1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package jsp2.examples.simpletag;
19
20 import javax.servlet.jsp.JspException;
21 import javax.servlet.jsp.tagext.JspFragment;
22 import javax.servlet.jsp.tagext.SimpleTagSupport;
23 import java.util.HashMap;
24 import java.io.IOException;
25
26 /**
27 * SimpleTag handler that accepts takes three attributes of type
28 * JspFragment and invokes then in a random order.
29 */
30 public class ShuffleSimpleTag extends SimpleTagSupport {
31 private JspFragment fragment1;
32 private JspFragment fragment2;
33 private JspFragment fragment3;
34
35 public void doTag() throws JspException, IOException {
36 switch( (int)(Math.random() * 6) ) {
37 case 0:
38 fragment1.invoke( null );
39 fragment2.invoke( null );
40 fragment3.invoke( null );
41 break;
42 case 1:
43 fragment1.invoke( null );
44 fragment3.invoke( null );
45 fragment2.invoke( null );
46 break;
47 case 2:
48 fragment2.invoke( null );
49 fragment1.invoke( null );
50 fragment3.invoke( null );
51 break;
52 case 3:
53 fragment2.invoke( null );
54 fragment3.invoke( null );
55 fragment1.invoke( null );
56 break;
57 case 4:
58 fragment3.invoke( null );
59 fragment1.invoke( null );
60 fragment2.invoke( null );
61 break;
62 case 5:
63 fragment3.invoke( null );
64 fragment2.invoke( null );
65 fragment1.invoke( null );
66 break;
67 }
68 }
69
70 public void setFragment1( JspFragment fragment1 ) {
71 this.fragment1 = fragment1;
72 }
73
74 public void setFragment2( JspFragment fragment2 ) {
75 this.fragment2 = fragment2;
76 }
77
78 public void setFragment3( JspFragment fragment3 ) {
79 this.fragment3 = fragment3;
80 }
81 }