2013-12-16 118 views
0

我创建了一个在本地驱动器中的word文档,它应该在浏览器中使用grails gsp页面打开。关于-Grails GSP

什么是创建是否创建链接或使用脚本的选项。 在此先感谢您的帮助。

回答

0

我不知道有任何插件可以让你直接在浏览器/ grails应用程序中渲染word文档。旧版本的Word & IE 7/8以前可能会有这种情况,但这种情况已不再存在。

一个Word文档基本上是一个XML文档,它具有各种标记,告诉文本如何渲染等,你可以看看加载这种格式。有人可能以前做过这个,所以如果你想调查这个选项,我会建议谷歌“word文档解析”或类似的。另一方面,如果您只对文档文本感兴趣,也许可以将word文档保存为txt文件?

希望有所帮助。

1

被打开或下载有很多的选择

  1. 是使用文件阅读器的Grails插件Grails File Plugin

  2. 只是提供链接,在.gsp文件,如下做出了downloadview option/open选项当您按下该文件的链接使用下面的代码。

在表列表

表明把这个代码,以使现有的文件中获取的从数据库里你下载的作用下,链接或其他来源

<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要下载或基于浏览浏览器选项

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() 
     } 
    } 

只是让我现在什么.. ..。 。