1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| package examples; |
17 |
| |
18 |
| |
19 |
| import javax.servlet.*; |
20 |
| import javax.servlet.jsp.*; |
21 |
| import javax.servlet.jsp.tagext.*; |
22 |
| |
23 |
| import java.io.*; |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class ShowSource |
29 |
| extends TagSupport |
30 |
| { |
31 |
| String jspFile; |
32 |
| |
33 |
0
| public void setJspFile(String jspFile) {
|
34 |
0
| this.jspFile = jspFile;
|
35 |
| } |
36 |
| |
37 |
0
| public int doEndTag() throws JspException {
|
38 |
0
| if ((jspFile.indexOf( ".." ) >= 0) ||
|
39 |
| (jspFile.toUpperCase().indexOf("/WEB-INF/") != 0) || |
40 |
| (jspFile.toUpperCase().indexOf("/META-INF/") != 0)) |
41 |
0
| throw new JspTagException("Invalid JSP file " + jspFile);
|
42 |
| |
43 |
0
| InputStream in
|
44 |
| = pageContext.getServletContext().getResourceAsStream(jspFile); |
45 |
| |
46 |
0
| if (in == null)
|
47 |
0
| throw new JspTagException("Unable to find JSP file: "+jspFile);
|
48 |
| |
49 |
0
| InputStreamReader reader = new InputStreamReader(in);
|
50 |
0
| JspWriter out = pageContext.getOut();
|
51 |
| |
52 |
| |
53 |
0
| try {
|
54 |
0
| out.println("<body>");
|
55 |
0
| out.println("<pre>");
|
56 |
0
| for(int ch = in.read(); ch != -1; ch = in.read())
|
57 |
0
| if (ch == '<')
|
58 |
0
| out.print("<");
|
59 |
| else |
60 |
0
| out.print((char) ch);
|
61 |
0
| out.println("</pre>");
|
62 |
0
| out.println("</body>");
|
63 |
| } catch (IOException ex) { |
64 |
0
| throw new JspTagException("IOException: "+ex.toString());
|
65 |
| } |
66 |
0
| return super.doEndTag();
|
67 |
| } |
68 |
| } |
69 |
| |
70 |
| |
71 |
| |
72 |
| |