grails - 在grails中上传PDF

标签 grails file-upload upload gsp

我需要以我在文本和在线中查看过的PDF上载grails。这是我到目前为止在 Controller 中拥有的

def upload = {
    def f = request.getFile('myFile')
    if(!f.empty) {
        f.transferTo( new File('/some/local/dir/myfile.txt') )
        response.sendError(200,'Done');
    } else {
        flash.message = 'file cannot be empty'
        render(view:'uploadForm')
    }
}

在 View 中,我在_forms View 中
    <g: uploadForm action="upload">
<input type="file" name="myFile"/>
<input type= "submit" value="Upload"/>
</g: uploadForm>

当我转到创建页面时,出现错误。

我得到这个错误
Grails标记[g:]未关闭。 Stacktrace如下:
Message: Error processing GroovyPageView: Grails tag [g:] was not closed
Line | Method
->>  461 | doFilter  in \grails-app\views\report\create.gsp

Caused by GrailsTagException: Grails tag [g:] was not closed
->>   36 | doCall    in C:/Users/Owner/Desktop/grails-app/views/report/create.gsp

关于如何清除错误的任何建议?当我删除_forms View 中的附加内容时,错误就消失了。我看不到未关闭的标签

要求的完整gsp
<div class="fieldcontain ${hasErrors(bean: reportInstance, field: 'location', 'error')} required">
    <label for="location">
        <g:message code="report.location.label" default="Location" />
        <span class="required-indicator">*</span>
    </label>
    <g:select id="location" name="location.id" from="${lc.Location.list()}" optionKey="id" required="" value="${reportInstance?.location?.id}" class="many-to-one"/>
</div>

<div class="fieldcontain ${hasErrors(bean: reportInstance, field: 'published', 'error')} required">
    <label for="published">
        <g:message code="report.published.label" default="Published" />
        <span class="required-indicator">*</span>
    </label>
    <g:datePicker name="published" precision="day"  value="${reportInstance?.published}"  />
</div>

<div class="fieldcontain ${hasErrors(bean: reportInstance, field: 'title', 'error')} ">
    <label for="title">
        <g:message code="report.title.label" default="Title" />

    </label>
    <g:textField name="title" value="${reportInstance?.title}"/>
</div>

<div class="fieldcontain ${hasErrors(bean: reportInstance, field: 'myFile', 'error')} ">
    <label for="myFile">
        <g:uploadForm action="upload"/>
    <input type="file" name="myFile"/>
    <input type= "submit" value="Upload"/>
    </g:uploadForm>

    </label>
</div>

最佳答案

从中删除/

<g:uploadForm action="upload"/>

这应该是
<g:uploadForm action="upload">
    ....
</g:uploadForm>

关于grails - 在grails中上传PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20289507/

相关文章:

database - Grails 自动约束更新

javascript - 使用 AngularJS 和 PHP 上传文件

iOS 分段上传照片

javascript - 使用 Jquery 设置文件输入样式

session - Laravel 5.1 使用 session.upload_progress

php - 警告 : move_uploaded_file(): open_basedir restriction in effect. File() 不在允许的路径内:

tomcat - 具有使用多个数据源的 spring 安全核心的 Grails 3.1.8

unit-testing - 使用复合键的Grails单元测试

Grails 2 应用程序无法在 JBOSS 上部署 : BeanCreationException

file - 从 Access 2010 上传文件