1 25 package examples; 26 27 28 import javax.servlet.*; 29 import javax.servlet.jsp.*; 30 import javax.servlet.jsp.tagext.*; 31 32 import java.io.*; 33 34 37 public class ShowSource 38 extends TagSupport 39 { 40 String jspFile; 41 42 public void setJspFile(String jspFile) { 43 this.jspFile = jspFile; 44 } 45 46 public int doEndTag() throws JspException { 47 if ((jspFile.indexOf( ".." ) >= 0) || 48 (jspFile.toUpperCase().indexOf("/WEB-INF/") != 0) || 49 (jspFile.toUpperCase().indexOf("/META-INF/") != 0)) 50 throw new JspTagException("Invalid JSP file " + jspFile); 51 52 InputStream in 53 = pageContext.getServletContext().getResourceAsStream(jspFile); 54 55 if (in == null) 56 throw new JspTagException("Unable to find JSP file: "+jspFile); 57 58 InputStreamReader reader = new InputStreamReader(in); 59 JspWriter out = pageContext.getOut(); 60 61 62 try { 63 out.println("<body>"); 64 out.println("<pre>"); 65 for(int ch = in.read(); ch != -1; ch = in.read()) 66 if (ch == '<') 67 out.print("<"); 68 else 69 out.print((char) ch); 70 out.println("</pre>"); 71 out.println("</body>"); 72 } catch (IOException ex) { 73 throw new JspTagException("IOException: "+ex.toString()); 74 } 75 return super.doEndTag(); 76 } 77 } 78 79 80 81 82 | Popular Tags |