處理html解析問題,處理html解析

來源:互聯網
上載者:User

處理html解析問題,處理html解析

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;/* * @功能介紹 擷取HTML的三中方式 *  * 時間 2015-04-08 22:11:00; *  * 開發人員  :楊英 */public class HtmlDaoImp implements HtmlDao{public String getHtmlFile(String 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 BufferedReader(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<String> 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 "";}}
通過Json的形式替換吊頁面的內容,就不用一個個的去寫值了。


JsonObject ,這個資料從業務層擷取,自己組裝。HTML是模版裡面定義的內容,key對應著對應的內容,進行替換掉。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.