public int doEndTag() throws JspException {
    if ((jspFile.indexOf("..") >= 0)
        || (jspFile.toUpperCase().indexOf("/WEB-INF/") != 0)
        || (jspFile.toUpperCase().indexOf("/META-INF/") != 0))
      throw new JspTagException("Invalid JSP file " + jspFile);

    InputStream in = pageContext.getServletContext().getResourceAsStream(jspFile);

    if (in == null) throw new JspTagException("Unable to find JSP file: " + jspFile);

    InputStreamReader reader = new InputStreamReader(in);
    JspWriter out = pageContext.getOut();

    try {
      out.println("<body>");
      out.println("<pre>");
      for (int ch = in.read(); ch != -1; ch = in.read())
        if (ch == '<') out.print("&lt;");
        else out.print((char) ch);
      out.println("</pre>");
      out.println("</body>");
    } catch (IOException ex) {
      throw new JspTagException("IOException: " + ex.toString());
    }
    return super.doEndTag();
  }
  public void doTag() throws JspException, IOException {

    JspContext ctx = getJspContext();
    JspWriter out = ctx.getOut();

    int sum = num1 + num2;
    ctx.setAttribute("sum", Integer.toString(sum));

    out.println(num1 + " + " + num2 + " = " + sum);
  }
Example #3
0
  public int doStartTag() {
    try {
      JspWriter out = pageContext.getOut();
      out.print(
          "<TABLE BORDER=" + border + " BGCOLOR=\"" + bgColor + "\"" + " ALIGN=\"" + align + "\"");
      if (width != null) {
        out.print(" WIDTH=\"" + width + "\"");
      }
      out.print("><TR><TH>");
      out.print(
          "<SPAN STYLE=\"" + "font-size: " + fontSize + "px; " + "font-family: " + fontList + "; ");

      if (color != null) {
        out.println("color: " + color + ";");
      }
      out.print("\"> "); // End of <SPAN ...>
    } catch (IOException ioe) {
      System.out.println("Error in HeadingTag: " + ioe);
    }
    return (EVAL_BODY_INCLUDE); // Include tag body
  }