struts2把html生成pdf,Struts2将Word文件数据,提取成HTML页面,显示在浏览器中

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

分享一个刚写的小例子给大家

import java.io.File;import java.io.IOException;import org.apache.commons.io.FileUtils;import org.apache.struts2.ServletActionContext;import org.apache.struts2.convention.annotation.Action;import org.apache.struts2.convention.annotation.Namespace;import org.apache.struts2.convention.annotation.ParentPackage;import org.apache.struts2.convention.annotation.Result;import org.apache.struts2.convention.annotation.Results;import com.jacob.activeX.ActiveXComponent;import com.jacob.com.Dispatch;import com.jacob.com.Variant;@ParentPackage("struts-default")@Namespace("/word")@Action("getWord")@Results({ @Result(name = "success",location = "/images/aaaa.html") })@SuppressWarnings("all")public class GetWordAction { public String getWord(){ ActiveXComponent app = new ActiveXComponent("Word.Application"); app.setProperty("Visible", new Variant(false)); Dispatch doc1 = app.getProperty("Documents").toDispatch(); //打开aaaa.doc Dispatch doc2 = Dispatch.invoke( doc1, "Open", Dispatch.Method, new Object[]{"d://tt.doc", new Variant(false), new Variant(true)}, new int[1] ).toDispatch(); //另存为aaaa.html String name="aaaa.html"; Dispatch.invoke( doc2, "SaveAs", Dispatch.Method, new Object[]{ "d://"+name, new Variant(8)//7为txt格式, 8保存为html格式 }, new int[1] ); Variant f = new Variant(false); Dispatch.call(doc2, "Close", f); File file = new File("d://aaaa.html"); String realPath = ServletActionContext.getServletContext() .getRealPath("/images"); File filetemp = new File(realPath); File f1 = new File(filetemp, "aaaa.html"); try { FileUtils.copyFile(file, f1); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return "success"; }}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
本书由国内极为资深的Struts2技术专家(网名:downpour)亲自执笔,iteye兼CSDN产品总监范凯(网名:robbin)以及51CTO等技术社区鼎力推荐。   本书以Struts2的源代码为依托,通过对Struts2的源代码的全面剖析深入探讨了Struts2的架构设计、实现原理、设计理念与设计哲学,对从宏观上和微观上去了解Struts2的技术内幕提供了大量真知灼见。同样重要的是,本书还深入挖掘并分析了Struts2源代码实现蕴含的大量值得称道的编程技巧和设计模式,这对开发者从Struts2的设计原理上去掌握和悟透Web层开发的要点和本质提供了绝佳的指导。   本书主要分为3大部分,内容安排具有极强的逻辑推理性,章和章之间互相呼应且互为印证。知识准备篇首先介绍了获取、阅读和调试Struts2源代码的方法,以及Struts2源代码的组织形式;然后厘清了Web开发极易混淆的一些重要概念,以及Struts2的核心技术、宏观视图、微观元素、配置元素等,提纲挈领地对Struts2进行了多角度的讲解。核心技术篇首先分析了Struts2多种具有代表性的设计模式,然后对Struts2的精华——OGNL表达式引擎和XWork框架的原理及机制进行了全面深入的分析和讲解。运行主线篇首先对Struts2的两大运行主线——初始化主线和HTTP请求处理主线进行了深入的剖析,然后对Struts2的扩展机制进行了解读和抽象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值