Html utilities : HTML Output « Servlets « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Servlets » HTML OutputScreenshots 
Html utilities


import java.io.IOException;
import java.io.StringWriter;
import java.util.Vector;

public class HtmlUtils {

  public String createHtmlHeader(String title) {

    String htmlHeader = null;
    htmlHeader = "<HTML><HEAD><TITLE> " + title + " </TITLE></HEAD><BODY>";
    return htmlHeader;
  }

  public String getHtmlFooter() {

    String htmlFooter = "</BODY></HTML>";
    return htmlFooter;
  }

  public String getHead(int level, String heading) {
    return "<H" + level + "> " + heading + "</H" + level + ">";
  }

  public String getTableHead(String align, int border) {

    String tableHeader = null;
    tableHeader = "<TABLE align=" + align + " border=" + border + ">";
    return tableHeader;

  }

  public String getTR(String align) {
    String TRCell = null;
    TRCell = "<TR align=" + align + ">";
    return TRCell;
  }

  public String getTR() {
    String TRCell = null;
    TRCell = "<TR>";
    return TRCell;
  }

  public String getTD(String align, String value) {
    String TDCell = null;
    TDCell = "<TD align=" + align + "> " + value + " </TD>";
    return TDCell;
  }

  public String getTD() {
    String TDCell = null;
    TDCell = "<TD>";
    return TDCell;
  }

  public String getTD(int width) {
    String TDCell = null;
    TDCell = "<TD WIDTH=" + width + ">";
    return TDCell;
  }

  public String getTH(String align, String value) {
    String THCell = null;
    THCell = "<TH align=" + align + "> " + value + " </TH>";
    return THCell;
  }

  public String getTableContents(String align, Vector values,
      int elementCounterthrows IOException {

    StringWriter Cells = new StringWriter();
    String contents = new String();
    int vsize = values.size();

    Cells.write("<TR>");

    for (int i = 0; i < vsize; i++) {
      String value = values.elementAt(i).toString();

      if (i != 0) {
        if (i >= elementCounter) {

          if (i % elementCounter == 0) {
            Cells.write("</TR>\n\n<TR>");
          }
        }
      }

      Cells.write("<TD align=" + align + "> " + value + " </TD> \n");
    }

    Cells.write("</TR>");

    contents = Cells.toString();
    Cells.flush();
    Cells.close();

    return contents;
  }

  public String getClosedTR() {
    String TRCell = null;
    TRCell = "</TR>";
    return TRCell;
  }

  public String getClosedTD() {
    String TDCell = null;
    TDCell = "</TD>";
    return TDCell;
  }

  public String getBR(int lines) {

    StringWriter lineBR = new StringWriter();
    String lineBRs = new String();

    for (int i = 0; i <= lines; i++) {
      lineBR.write("<BR>\n");
    }
    lineBRs = lineBR.toString();

    return lineBRs;
  }

  public String getLI(String item) {

    String li = new String("<LI>");
    li += item;
    return li;

  }
}

           
       
Related examples in the same category
1. Servlet Output HTML Demo
2. Servlet Display Static HTML
3. Prints a conversion table of miles per gallon to kilometers per liter
4. Servlet: Print Table
5. Html Parse Servlet
w___w___w_.j__av__a___2_s___.___c___o_m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.