Handle html parsing problems

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.