处理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 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();
	}

}
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 "";
	}
}
通过Json的形式替换吊页面的内容,就不用一个个的去写值了。


JsonObject ,这个数据从业务层获取,自己组装。HTML是模版里面定义的内容,key对应着对应的内容,进行替换掉。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值