Home> Java> javaTutorial> body text

Generate html files using java

高洛峰
Release: 2016-12-19 09:19:03
Original
1595 people have browsed it

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("
"); List> result1 = getRpt(sqlProperties .getProperty("sql1")); for (Map.Entry m : result1.get(0).entrySet()) { sb.append(fileProperties.getProperty("file1")); sb.append(m.getValue()); } sb.append("

");
Copy after login

The output is also very simple.

sb.append("
"); printStream.println(sb.toString());
Copy after login

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.

Generate html files using java

Here is an example I wrote

sb.append(""); for (Map.Entry m : result.get(0).entrySet()) { sb.append(""); } sb.append(""); for (int i = 0; i < result.size(); i++) { sb.append(""); for (Map.Entry m : result.get(i).entrySet()) { sb.append(""); } sb.append(""); } sb.append("
"); sb.append(m.getKey()); sb.append("
"); sb.append(m.getValue()); sb.append("
");
Copy after login



For more articles related to using java to generate html files, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!