NutzCN Logo
问答 ajaxFileUpload 上传文件和json数据
发布于 2508天前 作者 qq_e79520c3 2755 次浏览 复制 上一个帖子 下一个帖子
标签:

@At("/saveMarker")
@Ok("json")
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:fileUpload" })

public Object addDo(@Param("infoJson") Rts_result_marker rtsResultMarker,@Param("points") RtsResultMeasurePointBean[] points,HttpServletRequest req,@Param("picsource") File f) {

------------------------------------------------------------------------
[DEBUG] 2018-02-09 14:59:28,355 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [POST]URI=/RealTiSystem/platform/RTS/result_marker/saveMarker 5ms
[WARN ] 2018-02-09 14:59:28,355 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/platform/RTS/result_marker/saveMarker :
org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.String> to <cn.wizzer.app.RTS.modules.models.result.Rts_result_marker> for {{}
at org.nutz.castor.Castors.cast(Castors.java:262)
at org.nutz.castor.Castors.castTo(Castors.java:316)
at org.nutz.mvc.adaptor.injector.NameInjector.get(NameInjector.java:93)
at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:255)
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:58)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
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)

----------------------------------------------------------------------
@Param("infoJson") Rts_result_marker rtsResultMarker @Param("picsource") File f 不能同时接收对象和文件么 ?

11 回复
[DEBUG] 2018-02-09 15:12:33,416 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil>
[DEBUG] 2018-02-09 15:12:33,417 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil>
[DEBUG] 2018-02-09 15:12:33,417 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil>
[DEBUG] 2018-02-09 15:12:33,417 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'rtsResultMarkerController'<class cn.wizzer.app.web.modules.controllers.platform.RTS.result.RtsResultMarkerController>
[DEBUG] 2018-02-09 15:12:33,417 org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:184) - Select Html4 Form upload parser --> /RealTiSystem/platform/RTS/result_marker/saveMarker
[DEBUG] 2018-02-09 15:12:33,417 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:39) - FastUpload : /platform/RTS/result_marker/saveMarker
[DEBUG] 2018-02-09 15:12:33,418 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:54) - info created
[DEBUG] 2018-02-09 15:12:33,418 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:60) - Params map created - 0 params
[DEBUG] 2018-02-09 15:12:33,418 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:77) - boundary: 
------WebKitFormBoundaryunYH3GPaS5oVIu5b
[DEBUG] 2018-02-09 15:12:33,418 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:100) - skip first boundary
[DEBUG] 2018-02-09 15:12:33,419 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:111) - Reading...
[DEBUG] 2018-02-09 15:12:33,419 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[null],fieldName=[infoJson]
[DEBUG] 2018-02-09 15:12:33,419 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:214) - Found a param, name=[infoJson] value=[{]
[DEBUG] 2018-02-09 15:12:33,419 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[null],fieldName=[points]
[DEBUG] 2018-02-09 15:12:33,419 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:214) - Found a param, name=[points] value=[[{]
[DEBUG] 2018-02-09 15:12:33,420 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:231) - ...Done 235 bytes readed
[DEBUG] 2018-02-09 15:12:33,426 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [POST]URI=/RealTiSystem/platform/RTS/result_marker/saveMarker 10ms
[WARN ] 2018-02-09 15:12:33,426 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/platform/RTS/result_marker/saveMarker :
org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.String> to <cn.wizzer.app.RTS.modules.models.result.Rts_result_marker> for {{}
	at org.nutz.castor.Castors.cast(Castors.java:262)
	at org.nutz.castor.Castors.castTo(Castors.java:316)
	at org.nutz.mvc.adaptor.injector.NameInjector.get(NameInjector.java:93)
	at org.nutz.mvc.adaptor.AbstractAdaptor.adapt(AbstractAdaptor.java:255)
	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:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.XssSqlFilterProcessor.process(XssSqlFilterProcessor.java:35)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.NutShiroProcessor.process(NutShiroProcessor.java:52)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	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.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.GlobalsSettingProcessor.process(GlobalsSettingProcessor.java:36)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:21)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at cn.wizzer.app.web.commons.filter.RouteFilter.doFilter(RouteFilter.java:31)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
	at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
	at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
	at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
	at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
	at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
	at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:383)
	at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
	at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:94)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:504)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:502)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1132)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:684)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1533)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1489)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:748)
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'cn.wizzer.app.RTS.modules.models.result.Rts_result_marker'
 by args: [@({)]
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:988)
	at org.nutz.castor.castor.String2Object.cast(String2Object.java:16)
	at org.nutz.castor.castor.String2Object.cast(String2Object.java:9)
	at org.nutz.castor.Castors.cast(Castors.java:252)
	... 60 more

infoJson是字符串吧?先用字符串接收,然后toJson吧

恩恩,infoJson 在前端转为json了,我试下不转为json,用字符串接收

按json字符串接收,然后Json.fromJson


``` var objMeasure = {"title":null,"description":null,"type":null,"iconurl":null,"maptype":null,"picsource":null,"genre":null}; var infoJson = JSON.stringify(objMeasure); var pointsArray = JSON.stringify(points); $.ajaxFileUpload({ url: '../platform/RTS/result_marker/saveMarker', secureuri:false , fileElementId:'picsourceo', data:{ "infoJson":infoJson, "points":pointsArray }, dataType : 'json', success: function (data) { //返回json结果 ----------------------------------------- @At("/saveMarker") @Ok("json") @AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" }) public Object addDo(@Param("picsourceo") File f,HttpServletRequest req,@Param("infoJson") String rtsResultMarker,@Param("points")String points) { System.err.println("标注对象"); ------------------------------ [DEBUG] 2018-02-10 15:35:45,729 cn.wizzer.app.web.commons.processor.LogTimeProcessor.process(LogTimeProcessor.java:26) - [POST]URI=/RealTiSystem/platform/RTS/result_marker/saveMarker 59726ms [DEBUG] 2018-02-10 15:35:59,209 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) - ClusterManager: Check-in complete. [DEBUG] 2018-02-10 15:36:19,228 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) - ClusterManager: Check-in complete. [DEBUG] 2018-02-10 15:36:39,249 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) - ClusterManager: Check-in complete. [DEBUG] 2018-02-10 15:36:41,314 org.nutz.mvc.impl.UrlMappingImpl.get(UrlMappingImpl.java:101) - Found mapping for [POST] path=/platform/RTS/result_marker/saveMarker : RtsResultMarkerController.addDo(RtsResultMarkerController.java:96) [DEBUG] 2018-02-10 15:36:41,314 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'shiroUtil'<class cn.wizzer.framework.util.ShiroUtil> [DEBUG] 2018-02-10 15:36:41,314 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'dateUtil'<class cn.wizzer.framework.util.DateUtil> [DEBUG] 2018-02-10 15:36:41,314 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'stringUtil'<class cn.wizzer.framework.util.StringUtil> [DEBUG] 2018-02-10 15:36:41,314 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) - Get 'rtsResultMarkerController'<class cn.wizzer.app.web.modules.controllers.platform.RTS.result.RtsResultMarkerController> [DEBUG] 2018-02-10 15:36:41,315 org.nutz.mvc.upload.UploadAdaptor.getReferObject(UploadAdaptor.java:184) - Select Html4 Form upload parser --> /RealTiSystem/platform/RTS/result_marker/saveMarker [DEBUG] 2018-02-10 15:36:41,315 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:39) - FastUpload : /platform/RTS/result_marker/saveMarker [DEBUG] 2018-02-10 15:36:41,315 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:54) - info created [DEBUG] 2018-02-10 15:36:41,316 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:60) - Params map created - 0 params [DEBUG] 2018-02-10 15:36:41,316 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:77) - boundary: ------WebKitFormBoundarynzCx5LmQnedyvaM3 [DEBUG] 2018-02-10 15:36:41,316 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:100) - skip first boundary [DEBUG] 2018-02-10 15:36:41,316 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:111) - Reading... [DEBUG] 2018-02-10 15:36:41,317 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[null],fieldName=[infoJson] [DEBUG] 2018-02-10 15:36:41,317 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:214) - Found a param, name=[infoJson] value=[{] [DEBUG] 2018-02-10 15:36:41,317 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[null],fieldName=[points] [DEBUG] 2018-02-10 15:36:41,317 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:214) - Found a param, name=[points] value=[[{] [DEBUG] 2018-02-10 15:36:41,317 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:133) - Upload File info: FilePath=[2.jpg],fieldName=[picsourceo] [DEBUG] 2018-02-10 15:36:41,317 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:137) - Upload Info: name=2.jpg,content_type=image/jpeg [DEBUG] 2018-02-10 15:36:41,331 org.nutz.mvc.upload.FastUploading.parse(FastUploading.java:231) - ...Done 70802 bytes readed [DEBUG] 2018-02-10 15:36:59,310 org.quartz.impl.jdbcjobstore.JobStoreSupport$ClusterManager.manage(JobStoreSupport.java:3877) - ClusterManager: Check-in complete. 后台不报错,debug看 用String 接收 的rtsResultMarker 就一个是 " { "

@wendal ,求助 ,
感觉 @AdaptBy(type = UploadAdaptor.class, args = { "${app.root}/WEB-INF/tmp" }) 影响了 适配

我觉得更像这个js插件的不过,看看请求里面是否有完整的json字符串吧

有完整的数据, 但是就是只获取了一个 { ,或者换种方式获取的
就是 OBject Object

@AdaptBy(type=JsonAdaptor.class) 这个 ,又不能加,因为加了那个 文件上传的 适配器了

有个变通的办法,base64转换一下试试

想了想,可能是json字符串里面换行了

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