PageOffice最简集成代码(SpringMVC)

本文描述了PageOffice产品在SpringMVC项目中如何集成调用。

  1. 新建SpringMVC项目:pageoffice6-springmvc-simple
  2. 在您项目的pom.xml中通过下面的代码引入PageOffice依赖。pageoffice.jar已发布到Maven中央仓库 (opens new window),建议使用最新版本。
xml 复制代码
<dependency>
  <groupId>com.zhuozhengsoft</groupId>   
  <artifactId>pageoffice</artifactId>   
  <version>6.6.1.1-javax</version>
</dependency>
  1. 在您项目的web.xml配置PageOffice的服务器端servlet程序,添加如下代码:
xml 复制代码
    <servlet>
        <servlet-name>poserver</servlet-name>
        <servlet-class>com.zhuozhengsoft.pageoffice.poserver.Server</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/poserver.zz</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/sealsetup.exe</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/poclient</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>poserver</servlet-name>
        <url-pattern>/pageoffice.js</url-pattern>
    </servlet-mapping>
    <!--PageOffice V6.6新增以下powserver配置,PageOffice V6.5及以前的版本无需此配置 -->
    <!--
        PowServer跨域安全配置说明:
        1. 生产环境强烈建议避免使用通配符"*",应明确配置允许访问的具体来源
        2. 格式规范:多个地址使用逗号分隔,格式为"域名或IP地址列表"
        注意:本地开发环境地址(localhost,127.0.0.1)也必须在此配置
        3. 典型配置示例:
        单体多入口应用:"主域名,备用域名,服务器IP地址"
            示例值:"www.oa.com,oa.example.com,192.168.1.200"
    -->
    <context-param>
        <param-name>powserver-allowedOrigins</param-name>
        <param-value>*</param-value>
    </context-param>
    <listener>
        <listener-class>com.zhuozhengsoft.pageoffice.poserver.POWContextListener</listener-class>
    </listener>
  1. 在pageoffice6-springmvc-simple/src/main/webapp/WEB-INF目录下新建lib文件夹,拷贝PageOffice客户端安装程序到此目录下。比如:

    • Windows客户端安装程序:posetup_6.6.1.1.exe
    • 国产版操作系统客户端安装程序:对应芯片的PageOffice客户端deb安装包;

PageOffice客户端安装程序下载地址:www.zhuozhengsoft.com/dowm/(opens...

  1. 在pageoffice6-springmvc-simple/src/main/webapp目录下新建doc文件夹,准备一个有内容test.docx文件。新建Controller并调用PageOffice打开此文件,例如:
java 复制代码
@Controller
@RequestMapping("Document")
public class DocumentController {

    @RequestMapping("/openFile")
    public ModelAndView openFile(HttpServletRequest request, Map<String, Object> map) throws Exception{
        //******************************卓正PageOffice组件的使用*******************************
        PageOfficeCtrl poCtrl = new PageOfficeCtrl(request);
        poCtrl.setSaveFilePage("saveFile");
        //打开Word文档
        poCtrl.webOpen("/doc/test.docx", OpenModeType.docNormalEdit, "张三");
        map.put("pageoffice", poCtrl.getHtml());
        ModelAndView mv = new ModelAndView("Document/openFile");
        return mv;
    }

    @RequestMapping("/saveFile")
    public void saveFile(HttpServletRequest request, HttpServletResponse response) throws Exception{
        FileSaver fs = new FileSaver(request, response);
        fs.saveToFile(request.getSession().getServletContext().getRealPath("doc/")+fs.getFileName());
        fs.close();
    }
}
  1. 为上一步代码中的的ModelAndView准备页面。新建Document/openFile.jsp,在页面中添加下面的代码用来嵌入PageOffice控件:
css 复制代码
<div style=" width:auto; height:800px;">
    ${pageoffice}
</div>
  1. 在需要点击超链接在线打开文件的页面添加pageoffice.js的引用。
xml 复制代码
<script type="text/javascript" src="/pageoffice.js"></script>
  1. 编写打开文件的超链接代码。调用POBrowser的openWindow方法弹出窗口访问Controller方法Document/openFile在线打开文件。
css 复制代码
<a href="javascript:POBrowser.openWindow('Document/openFile','width=1150px;height=900px;');">
    在线打开文档
</a>
  1. 启动项目,点击"在线打开文档"超链接,查看在线打开编辑保存Office文件的效果。

参考链接:PageOffice最简集成代码(SpringMVC) | PageOffice 开发者中心

相关推荐
哦虎!12 小时前
【JavaEE】网络初识
java
for_ever_love__13 小时前
MySQL ORDER BY 排序优化:从 Using filesort 到索引有序扫描(含双路 / 单路排序原理)
java·mysql·优化·存储·by·order·filesort
大鸡腿同学13 小时前
手心向上,手心向下
后端
我是人✓13 小时前
Java文件上传三方式对比:从传统到SpringBoot
java·开发语言
欣栀♡14 小时前
JVM 频繁 Full GC 先看日志括号里的 cause,jstat 的 FGC 在 JDK 8 上会骗人
java·jvm
CCblandy14 小时前
令牌桶在 0.9 倍负载超发 19%、固定窗口边界放行 20 个:四种限流算法同构实测
后端·python·算法·性能优化·架构
IT研究室14 小时前
最新计算机毕业设计选题推荐-基于spring boot的葡萄酒文化宣传网站-网站-文档指导-Java-springboot
java·spring boot·课程设计
慧都小项14 小时前
MyEclipse 中创建和测试 JAX-RS REST 接口:从项目配置到 REST Explorer
java·restful·myeclipse·jax-rs
Wang's Blog14 小时前
Java 项目实战: 交友项目 - 入门案例:编写 Dubbo 服务提供者
java·dubbo·交友
秋饼15 小时前
Spring AI 2.0 结构化输出企业级实战:从 BeanOutputConverter 源码到生产级解析容错
java·ai·技术分享·后端开发