The principle is similar to using Java to generate jsp servlet. We can use printStream to output data to html files.
First create a StringBuilder object and add html statements to it through the append method. As shown in the following example:
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("每日运营报表 "); sb.append(""); sb.append(" "); sb.append(""); sb.append(""); sb.append("
"); sb.append("
"); ListThe output is also very simple.
"); printStream.println(sb.toString());sb.append("
Upload another test html that I generated using java, but the online data has not been called yet. In practical applications, you can use sql statements and lists to fill tables.
Here is an example I wrote
sb.append("
"); sb.append(m.getKey()); sb.append(" | "); } sb.append("
---|
"); sb.append(m.getValue()); sb.append(" | "); } sb.append("
For more articles related to using java to generate html files, please pay attention to the PHP Chinese website!