The principle is similar to the servlet that generates JSP in Java. We can use PrintStream to output data to HTML files.
First, create a StringBuilder object and add an HTML statement to it by Append method. As shown in the following example:
Copy Code code as follows:
StringBuilder sb = new StringBuilder ();
Properties fileproperties = getProperties ("file");
Properties sqlproperties = getProperties ("SQL");
PrintStream PrintStream = new PrintStream (New FileOutputStream (
"report.html"));
Sb.append ("Sb.append ("Sb.append ("<title> daily Operation report </title>");
Sb.append ("<meta http-equiv=\" content-type\ "content=\" text/html; charset=utf-8\ "/>");
Sb.append ("<style type=\" text/css\ ">");
Sb.append ("Table{border-collapse:collapse;border-left:solid 1 #000000; Border-top:solid 1 #000000;p adding:5px} ");
Sb.append ("Th{border-right:solid 1 #000000; border-bottom:solid 1 #000000;}");
Sb.append ("Td{font:normal;border-right:solid 1 #000000; border-bottom:solid 1 #000000;}");
Sb.append ("</style>Sb.append ("<body bgcolor=\" #FFF8DC \ ">");
Sb.append ("<div align=\" Center\ ">");
Sb.append ("<br/>");
Sb.append ("<br/>");
list<map<string, object>> result1 = Getrpt (sqlproperties
. GetProperty ("SQL1"));
For (map.entry<string, object> m:result1.get (0). EntrySet ()) {
Sb.append (Fileproperties.getproperty ("file1"));
Sb.append (M.getvalue ());
}
Sb.append ("<br/><br/>");
Output, also very simple.
Copy Code code as follows:
Sb.append ("</div></body>Printstream.println (Sb.tostring ());
Upload a test HTML that I generated in Java, and I haven't called the online data yet. You can use the SQL statement, list to populate the table in practical application.
Here's an example I wrote
Copy Code code as follows:
Sb.append ("<table border=\" 1\ "><tr>");
For (map.entry<string, object> m:result.get (0). EntrySet ()) {
Sb.append ("<th>");
Sb.append (M.getkey ());
Sb.append ("</th>");
}
Sb.append ("</tr>");
for (int i = 0; i < result.size (); i++) {
Sb.append ("<tr>");
For (map.entry<string, object> m:result.get (i). EntrySet ()) {
Sb.append ("<td>");
Sb.append (M.getvalue ());
Sb.append ("</td>");
}
Sb.append ("</tr>");
}
Sb.append ("</table>");
That's the story. The episode is more exciting ~