Handle html parsing problems
package org.OutHtml.Dao;import java.io.FileNotFoundException;import java.io.IOException;public interface HtmlDao {public String getHtmlFile(String Path) throws IOException;public String getHtmlSql(String SqlHtml);public String getHtmlURL(String URL) throws IOException;}
Package org. outHtml. dao. imp; import java. io. bufferedReader; import java. io. fileReader; import java. io. IOException; import java. io. inputStreamReader; import java.net. malformedURLException; import java.net. URL; import java.net. URLConnection; import org. outHtml. dao. htmlDao;/** @ Function Description: method 3 for getting HTML ** time: 22:11:00,; ** developer: Yang Ying */public class HtmlDaoImp implements HtmlDao {public String getHtmlFile (Str Ing Path) throws IOException {// TODO Auto-generated method stubStringBuffer sb = new StringBuffer (); BufferedReader bufr = new BufferedReader (new FileReader (Path); String line = null; while (line = bufr. readLine ())! = Null) {sb. append (line);} return sb. toString ();} public String getHtmlSql (String SqlHtml) {// TODO Auto-generated method stubStringBuffer sb = new StringBuffer (); return null;} public String getHtmlURL (String urls) throws IOException {// TODO Auto-generated method stubStringBuffer sb = new StringBuffer (); URL url = new URL (urls); URLConnection conn = url. openConnection (); BufferedReader bufin = new Buffer EdReader (new InputStreamReader (conn. getInputStream (); String line = null; while (line = bufin. readLine ())! = Null) {sb. append (line) ;}return sb. toString ();}}
package org.OutHtml.Util;import java.util.Iterator;import org.json.JSONException;import org.json.JSONObject;public class JsonOutHtml {public String getHtml(JSONObject o,String HTML){Iterator
keys=o.keys(); try {while(keys.hasNext()){ String key=keys.next(); HTML = HTML.replace(key, String.valueOf(o.get(key)));} } catch (JSONException e) {// TODO Auto-generated catch blocke.printStackTrace();} return "";}}
If you use Json to replace the content of a hanging page, you do not need to write values one by one.
JsonObject, which is obtained from the business layer and assembled by itself. HTML is the content defined in the template. The key corresponds to the corresponding content and is replaced.