nutzam / nutz

Nutz -- Web Framework(Mvc/Ioc/Aop/Dao/Json) for ALL Java developer
https://nutzam.com
Apache License 2.0
2.53k stars 942 forks source link

使用 jquery form plugin 进行ajax表单提交 表单中存在input type="file" 元素 #843

Closed hzl7652 closed 9 years ago

hzl7652 commented 9 years ago

使用 jquery form plugin 进行ajax表单提交 表单中存在input type="file" 元素 且,file元素没有选中文件提交时报出如下错误: java.lang.ClassCastException: java.lang.String cannot be cast to org.nutz.mvc.upload.TempFile at org.nutz.mvc.upload.injector.TempFileInjector.get(TempFileInjector.java:22) at org.nutz.mvc.upload.injector.TempFileInjector.get(TempFileInjector.java:12) at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:242) at org.nutz.mvc.upload.UploadAdaptor.adapt(UploadAdaptor.java:117) at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:28) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:40) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:113) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15) at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:40) at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:64) at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31) at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:182) at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1212) at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:399) at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216) at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182) at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:766) at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:450) at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152) at org.mortbay.jetty.Server.handle(Server.java:326) at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542) at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:945) at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:756) at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218) at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404) at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:410) at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

调试跟踪了一下,TempFileInjector.get 文件时,refer中的值为空字符串,所以报转换失败 但是普通的form表单提交,无文件没有报这个错误

hzl7652 commented 9 years ago

Accept:/ Accept-Encoding:gzip, deflate Accept-Language:zh-CN,zh;q=0.8 Cache-Control:no-cache Connection:keep-alive Content-Length:416 Content-Type:multipart/form-data; boundary=----WebKitFormBoundaryPxc18yyybKaotJH8 Cookie:JSESSIONID=1ocv3u9z1uh9x1btagy30v55ao; JSESSIONID=1h3zebda1ezdl1avwzri9em1uu; expandable=5c Host:localhost Origin:http://localhost Pragma:no-cache Referer:http://localhost/tjbb/admini-report/page?sys_menu=%E8%B4%A3%E6%9D%83%E6%8A%A5%E5%91%8A%E7%AE%A1%E7%90%86&sys_menuid=000200010004&sys_random=0.012673621764406562 User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36 X-Requested-With:XMLHttpRequest Request Payload ------WebKitFormBoundaryPxc18yyybKaotJH8 Content-Disposition: form-data; name="id"

------WebKitFormBoundaryPxc18yyybKaotJH8 Content-Disposition: form-data; name="title"

111 ------WebKitFormBoundaryPxc18yyybKaotJH8 Content-Disposition: form-data; name="fileN"

------WebKitFormBoundaryPxc18yyybKaotJH8 Content-Disposition: form-data; name="remark"

111 ------WebKitFormBoundaryPxc18yyybKaotJH8--