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 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对应着对应的内容,进行替换掉。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3101063.html