首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >关于-Grails GSP

关于-Grails GSP
EN

Stack Overflow用户
提问于 2013-12-16 13:24:15
回答 2查看 97关注 0票数 0

我在本地驱动器中创建了一个word文档,应该可以使用grails gsp页面在浏览器中打开它。

创建、创建链接或使用脚本的选项有哪些。提前感谢您的帮助。

EN

回答 2

Stack Overflow用户

发布于 2013-12-16 15:29:30

要打开或下载有很多选项

  1. 将使用文件查看器Grails插件Grails File Plugin
  2. Just在您的.gsp文件中提供链接,如下所示,并在使用以下代码按下该文档的链接时设置downloadview option/open选项。

在表格列表中显示从数据库或某些其他来源获取链接

代码语言:javascript
复制
<table>

        <thread>
        <tr>
            <g:sortableColumn property="filename" title="Filename" />
            <g:sortableColumn property="upload" title="Upload Date" />
        </tr>
        </thread>
        <tbody>
            <g:each in="${documentInstanceList}" status="i"
                var="documentInstance">
                <tr class="${(i%2)==0?'even':'odd'}">
                    <td><g:link action="download" id="${documentInstance.id}">
                            ${documentInstance.filename}
                        </g:link></td>
                    <td><g:formatDate date="${documentInstance.uploadDate}" /></td>
            </g:each>
        </tbody>
    </table>

在您的DocumentController中,在download操作下放入此代码,以使文件可根据浏览器选项进行下载或查看

代码语言:javascript
复制
def download(long id) {
        Document documentInstance = Document.get(id)
        if (documentInstance == null) {
            flash.message = "Document not found."
            redirect(action:'list')
        }

        else {

            response.setContentType("APPLICATION/OCTET-STREAM")
            response.setHeader("Content-Disposition","Attachment;Filename=\"${documentInstance.filename}\"")

            def file = new File(documentInstance.fullpath)
            def fileInputStream = new FileInputStream(file)

            def outputStream = response.getOutputStream()

            byte[] buffer = new byte[4096];
            int len ;
            while((len = fileInputStream.read(buffer))>0) {
                outputStream.write(buffer,0,len);
            }

            outputStream.flush()
            outputStream.close()
            fileInputStream.close()
        }
    }

现在让我做任何事..。。。

票数 1
EN

Stack Overflow用户

发布于 2013-12-16 14:12:01

据我所知,没有任何插件可以让你在浏览器/ grails应用程序中直接呈现word文档。这在旧版本的Word和IE 7/8中是可能的,但现在不是这样了。

word文档基本上是一个XML文档,其中包含各种标记,告诉文本如何呈现等,您可以考虑加载此格式。以前可能有人这样做过,所以如果你想研究这个选项,我建议你搜索"word文档解析“或类似的东西。另一方面,如果您只对文档文本感兴趣,也许可以将word文档保存为txt?

希望这能有所帮助。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20604017

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档