NutzCN Logo
问答 java.lang.ClassCastException: java.lang.String cannot be cast to org.nutz.mvc.upload.TempFile
发布于 2391天前 作者 AlinzZ 1610 次浏览 复制 上一个帖子 下一个帖子
标签:

1、Nutz Version : 1.b.51
2、后台入口代码:
@At
@Ok("json")
@AdaptBy(type = UploadAdaptor.class, args = {"${app.root}/WEB-INF/resource/tmp"})
public void addResource(Ioc ioc, HttpServletRequest request, @Param("..") Resource resource, @Param("pdfFile") TempFile temp) {
. . .
}
3、前端表单post值
------WebKitFormBoundaryABm4cUNAi3xJ8CkU
Content-Disposition: form-data; name="status"

0
------WebKitFormBoundaryABm4cUNAi3xJ8CkU
Content-Disposition: form-data; name="type"

2
------WebKitFormBoundaryABm4cUNAi3xJ8CkU
Content-Disposition: form-data; name="pdfFile"

------WebKitFormBoundaryABm4cUNAi3xJ8CkU
Content-Disposition: form-data; name="id"

0
------WebKitFormBoundaryABm4cUNAi3xJ8CkU
Content-Disposition: form-data; name="content"

fdsafdsafdsa
------WebKitFormBoundaryABm4cUNAi3xJ8CkU--

4、前端上传文件控件pdfFile没上传文件,提交到后台报错:
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:1)
at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:222)
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:99)
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.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)

```

2 回复

没选文件报错是一个很老的问题了

可以升级nutz版本,或者TempFile 改成Object 来接,然后代码判断一下类型

好的,谢谢兽总

添加回复
请先登陆
回到顶部