Home > Web Front-end > HTML Tutorial > Handling html parsing issues_html/css_WEB-ITnose

Handling html parsing issues_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:46:41
Original
1052 people have browsed it

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;}
Copy after login

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 stub		StringBuffer 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 stub		StringBuffer sb = new StringBuffer();								return null;	}	public String getHtmlURL(String urls) throws IOException {		// TODO Auto-generated method stub		StringBuffer 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();	}}
Copy after login
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 block			e.printStackTrace();		} 		return "";	}}
Copy after login
Replace the content of the hanging page in the form of Json, so there is no need to write values ​​one by one.


JsonObject, this data is obtained from the business layer and assembled by yourself. HTML is the content defined in the template, and the key corresponds to the corresponding content and is replaced.

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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template