GOG 上传文件 问题 (已解决)

importExcel.gsp
<g:uploadForm action="upload" >
    <label>话费日期:</label><g:datePicker name="date" value="${new Date()}" precision="month" years="${2008..2010}" /><br/>
    <label>上传文件:</label><input name="excelfile" type="file"/><br/>
    <!-- <g:actionSubmit value="上传" /> -->
<input type='submit' value='上传'/>
    </g:uploadForm>


在controller中
def upload = {
     flash.message = "请上传文件"
        if(request instanceof MultipartHttpServletRequest){
            def f =request.getFile("excelfile")
            if(!f.empty){
                try{
                    excelService.save(f.inputStream)
                }catch(RuntimeException e){
                    flash.message = "多行没有找到对应的号码!"
                    flash.errors = excelService.errors
                    render(view:'error')
                }
            }else{
                flash.message ="没有上传文件"
            }
        }
    }


如果点击表单的上传,就会跳转到 http://localhost/bill/upload,但是提示的是404错误
如果直接输入 http://localhost/bill/upload的url的话是可以显示 页面的
各位有遇到这种情况麽
问题已经解决,用错tag了 actionSubmit不应用在这里

还有就是貌似上传的部分有bug,某老外也遇到了问题

http://stackoverflow.com/questions/206224/grails-file-upload-problems

解决办法:(我没有测试成功,我卡在上面那个部分了)
引用

if(request instanceof MultipartHttpServletRequest)
{
  MultipartHttpServletRequest mpr = (MultipartHttpServletRequest)request;  
  CommonsMultipartFile f = (CommonsMultipartFile) mpr.getFile("myFile");
  if(!f.empty)
    flash.message = 'success'
  else
   flash.message = 'file cannot be empty'
}   
else
  flash.message = 'request is not of type MultipartHttpServletRequest'

你可能感兴趣的:(F#,Flash,grails)