struts2中需要html文件吗,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"; }}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值