html页面转换为js,作为其他页面引入

今天遇到一使用要求,将html页面以js的形式提供给其它网站使用。其效果类似于iframe.
public void achieveId(){
ActionContext ac = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ac.get(ServletActionContext.HTTP_REQUEST);
String ledFile = "/gg/js/led.js";
String eleFile = "/gg/js/ele.js";
HashSet<TEsample> tEsamples = new HashSet<TEsample>();
HashSet<TEsample> tEsamplesEle = new HashSet<TEsample>();
try {
Workbook book1 = Workbook.getWorkbook(new File(request.getSession().getServletContext().getRealPath("/exhibit/lighting/2013/huace.xls")));
Sheet sheet1 = book1.getSheet(4);
int rownum = sheet1.getRows();
for(int r = random(rownum); r < rownum; r++){
Cell cell1 = sheet1.getCell(1, r);
String catalog = cell1.getContents();
int ind = catalog.indexOf("=");
if (ind > 0) {
String id = catalog.substring(ind+1);
TEsample tEsample = alightOodiiDao.queryEsampleById(Long.parseLong(id));
if(tEsample != null && tEsamples.size() < 5 && tEsamples.contains(tEsample) == false){
tEsamples.add(tEsample);
}
}
}
} catch (BiffException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

StringBuffer bf = new StringBuffer();
bf.append("<!DOCTYPE html PUBLIC \\\"-\\/\\/W3C\\/\\/DTD XHTML 1.0 Transitional\\/\\/EN\\\" \\\"http:\\/\\/www.w3.org\\/TR\\/xhtml1\\/DTD\\/xhtml1-transitional.dtd\\\">");
bf.append("<html xmlns=\\\"http:\\/\\/www.w3.org\\/1999/xhtml\\\">");
bf.append("<head>");
bf.append("<meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=UTF-8\\\" \\/>");
bf.append("<title>数据<\\/title>");
bf.append("<link href=\\\"http://www.oodii.com/v3/css/led.css\\\" rel=\\\"stylesheet\\\" type=\\\"text/css\\\" \\/>");
bf.append("<\\/head>");
bf.append("<body>");
bf.append("<div class=\\\"product_list\\\">");
bf.append("<div class=\\\"right_ad\\\"><a href=\\\"http://www.oodii.com/exhibit/lighting/2013/\\\" target=\\\"_blank\\\"><img src=\\\"http://www.oodii.com/v3/img/ledth_03.jpg\\\" width=\\\"152\\\" height=\\\"218\\\" \\/><\\/a><\\/div>");
if (tEsamples != null && tEsamples.size() > 0) {
Iterator it = tEsamples.iterator();
while (it.hasNext()) {
TEsample tEsample = (TEsample) it.next();
bf.append("<li>");
String picM = tEsample.getCoverPic();
if(picM.indexOf("_s") > 0){
picM = picM.replace("_s", "_m");
}
bf.append("<div class=\\\"img\\\"><a href=\\\"http://ecatalog.oodii.com/").append(tEsample.getId()).append(".html\\\" target=\\\"_blank\\\"><img src=\\\"http://image.oodii.com/").append(picM).append("\\\" width=\\\"120\\\" height=\\\"144\\\" \\/><\\/a><\\/div>");
bf.append("<div class=\\\"title\\\"><a title=\\\"").append(tEsample.getEsampleName()).append("\\\" href=\\\"http://www.oodii.com/catalog.action?id=").append(tEsample.getId())
.append("\\\" target=\\\"_blank\\\">").append(tEsample.getEsampleName()).append("<\\/a><\\/div>");
bf.append("<\\/li>");
}
}
bf.append("<\\/ul><\\/div><\\/body><\\/html>");
String wr = "document.writeln(\""+bf.toString()+"\");";
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter(new FileOutputStream(request.getSession().getServletContext().getRealPath(ledFile), false),"UTF-8");
osw.write(wr, 0, wr.length());
}catch(Exception ex){
ex.printStackTrace();
}finally{
try {
osw.flush();
osw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值