我遇到问题,请在Grails中上传文件。这有点奇怪,因为它在一种方法中工作但在其他方法中不起作用。这是我的代码:
HTML:
<table>
<tr>
<td>
<g:message code="application.image"/>
</td>
<td class="ImageCheck">
<input type="checkbox" id="ImageCheck" name="ImageCheck" onchange="Show();" />
</td>
</tr>
<tr>
<td class="fileInput_Class" ><input id="inputFile" type="file" name="main" style="display: none" onchange=check(this)'/>
</tr>
<table>
的Grails:
def ImageUpload()
{
def f = request.getFile('main')
if(f.fileItem.getSize()!=0)
{
"transferring file to specific location"
}
}
工作和失败的方法代码看起来是一样的,这里是一个堆栈跟踪:
[ERROR] [org.codehaus.groovy.grails.webflow.engine.builder.ClosureInvokingAction] - Exception occured invoking flow action: No signature of method: org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [main]
Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON()
groovy.lang.MissingMethodException: No signature of method: org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [main]
Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON()
at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
这解决了这个问题。
<td class="ImageCheck">
<g:form method="post" enctype"multipart/form-data">
<input type="checkbox" id="ImageCheck" name="ImageCheck" onchange="Show();"/>
<input type="submit" id="submitImage" name="sub" onClick="DoSomething()"/>
</g:form>
</td>
答案 0 :(得分:0)
我是瞎子:d,这解决了问题:
<td class="ImageCheck">
<g:form method="post" enctype"multipart/form-data">
<input type="checkbox" id="ImageCheck" name="ImageCheck" onchange="Show();"/>
<input type="submit" id="submitImage" name="sub" onClick="DoSomething()"/>
</g:form>
</td>