以grails格式上传PDF

时间:2013-11-29 15:59:35

标签: grails file-upload upload gsp

我需要在PDF中上传grails我在文本和在线查看。这是我目前在我的控制器中所拥有的

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

在视图中,我在_forms视图中有这个

    <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视图的添加时,错误就会消失。我看不到未关闭的标签

要求

的完整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>

1 个答案:

答案 0 :(得分:1)

中删除/
<g:uploadForm action="upload"/>

这应该是

<g:uploadForm action="upload">
    ....
</g:uploadForm>