求一个word文件上传下载的demo,不会配置upload.js
7 回复
有一个错误,请您指教一下
文件目录
src
--- com.xxxx.xxx.xxx
----common
---action
-- --- UploadFilesAction
conf
---custom
----db.properties
---ioc
--dao.js
--upload.js
upload.js代码
/**
* 系统文件上传配置
*/
var ioc = {
config : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["conf/custom/db.properties"]
},
utils : {
type : 'com.usts.management.common.util',
fields : {
sc : {
app : '$servlet'
} // 将 ServletContext 对象注入 MyUtils
}
},
tmpFilePool : {
type : 'org.nutz.filepool.NutFilePool',
// 临时文件最大个数为 1000 个
args : [{
refer : 'reportTempletPath'
}, 1000]
},
uploadFileContext : {
type : 'org.nutz.mvc.upload.UploadingContext',
singleton : false,
args : [{
refer : 'tmpFilePool'
}],
fields : {
// 单个文件最大尺寸(大约的值,单位为字节,即 1048576 为 1M)
// maxFileSize : 2097152,
// 正则表达式匹配可以支持的文件名
// nameFilter : '^(.+[.])(gif|jpg|png|xls|avi|rmvb)$',
// 是否忽略空文件, 默认为 false
ignoreNull : true
}
},
myUpload : {
type : 'org.nutz.mvc.upload.UploadAdaptor',
singleton : false,
args : [{
refer : 'uploadFileContext'
}]
},
// 临时目录
reportTempletPath : {
type : 'java.lang.String',
args : [{java :"$config.get('reportTempletPath')"}]
},
};
db.properties
#mysql
db.url=jdbc:mysql://127.0.0.1:3306/reportmanagement
db.username=root
db.password=123456
#db.validationQuery=select 1
db.maxActive=100
db.testWhileIdle=true
db.filters=mergeStat
db.connectionProperties=druid.stat.slowSqlMillis=2000
#db.defaultAutoCommit=true
#Template File Path
reportTempletPath=E:/reportsystem/temps
#official document
officialFilePath=F:/Java/Workplace03/ReportSystem/WebContent/wordtemp
UploadFilesAction
@IocBean
@InjectName
@At("upload")
public class UploadFilesAction extends BaseAction {
private static Logger log = LoggerFactory.getLogger(UploadFilesAction.class);
@At
@AdaptBy(type = UploadAdaptor.class, args = { "ioc:myUpload" })
public Object uploadFile(@Param("file") TempFile tf){
File f = tf.getFile(); // 这个是保存的临时文件
try {
log.debug("上传文件:[{}] 上传后的临时文件:[{}]", tf.getMeta().getFileLocalName(), f.getCanonicalPath()); //getCanonicalPath返回规范的绝对路径
return requestResult(true, f.getCanonicalPath());
} catch (IOException e) {
e.printStackTrace();
}
return requestResult(false, "");
}
错误信息
2017-05-10 16:42:27,221 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'myUpload'<class org.nutz.mvc.upload.UploadAdaptor>
2017-05-10 16:42:27,222 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get '$aop_async'<interface org.nutz.ioc.aop.config.AopConfigration>
2017-05-10 16:42:27,223 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=$aop_async
2017-05-10 16:42:27,224 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject($aop_async) in AsyncAopIocLoader@518410525
2017-05-10 16:42:27,225 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'$aop_async'<interface org.nutz.ioc.aop.config.AopConfigration>
2017-05-10 16:42:27,225 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object '$aop_async' to [app]
2017-05-10 16:42:27,229 org.nutz.ioc.aop.SimpleAopMaker.<init>(SimpleAopMaker.java:79) DEBUG - Load AopConfigure for anno=org.nutz.ioc.aop.Aop by type=org.nutz.ioc.aop.config.impl.AnnotationAopConfigration
2017-05-10 16:42:27,230 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=myUpload
2017-05-10 16:42:27,230 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=myUpload
2017-05-10 16:42:27,231 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(myUpload) in JsonLoader(paths=[ioc/])
2017-05-10 16:42:27,231 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'myUpload'<class org.nutz.mvc.upload.UploadAdaptor>
2017-05-10 16:42:27,235 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class org.nutz.mvc.upload.UploadAdaptor without AOP
2017-05-10 16:42:27,236 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'uploadFileContext'<>
2017-05-10 16:42:27,236 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=uploadFileContext
2017-05-10 16:42:27,236 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=uploadFileContext
2017-05-10 16:42:27,241 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(uploadFileContext) in JsonLoader(paths=[ioc/])
2017-05-10 16:42:27,241 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'uploadFileContext'<>
2017-05-10 16:42:27,242 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class org.nutz.mvc.upload.UploadingContext without AOP
2017-05-10 16:42:27,244 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'tmpFilePool'<>
2017-05-10 16:42:27,244 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=tmpFilePool
2017-05-10 16:42:27,244 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=tmpFilePool
2017-05-10 16:42:27,245 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(tmpFilePool) in JsonLoader(paths=[ioc/])
2017-05-10 16:42:27,245 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'tmpFilePool'<>
2017-05-10 16:42:27,246 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class org.nutz.filepool.NutFilePool without AOP
2017-05-10 16:42:27,246 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'tmpFilePool' to [app]
2017-05-10 16:42:27,246 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'reportTempletPath'<>
2017-05-10 16:42:27,246 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=reportTempletPath
2017-05-10 16:42:27,246 org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:67) DEBUG - Loading define for name=reportTempletPath
2017-05-10 16:42:27,246 org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:169) DEBUG - Found IocObject(reportTempletPath) in JsonLoader(paths=[ioc/])
2017-05-10 16:42:27,246 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:209) DEBUG - >> Make...'reportTempletPath'<>
2017-05-10 16:42:27,247 org.nutz.ioc.aop.impl.DefaultMirrorFactory.getMirror(DefaultMirrorFactory.java:70) DEBUG - Load class java.lang.String without AOP
2017-05-10 16:42:27,247 org.nutz.ioc.impl.ScopeContext.save(ScopeContext.java:64) DEBUG - Save object 'reportTempletPath' to [app]
2017-05-10 16:42:27,255 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'config'<>
2017-05-10 16:42:27,255 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:177) DEBUG - >> Load definition name=config
2017-05-10 16:42:27,255 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) DEBUG - Remove object 'reportTempletPath' from [app]
2017-05-10 16:42:27,256 org.nutz.ioc.impl.ScopeContext.remove(ScopeContext.java:84) DEBUG - Remove object 'tmpFilePool' from [app]
2017-05-10 16:42:27,256 org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:51) DEBUG - Eval FAIL!! : public java.lang.Object com.usts.management.common.action.UploadFilesAction.uploadFile(org.nutz.mvc.upload.TempFile)
org.nutz.ioc.IocException: [myUpload, uploadFileContext, tmpFilePool, reportTempletPath, config] # For object [config] - type:[]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at org.nutz.ioc.java.IocObjectNode.getValue(IocObjectNode.java:19)
at org.nutz.ioc.java.ChainNode.eval(ChainNode.java:24)
at org.nutz.ioc.java.ChainNode.eval(ChainNode.java:19)
at org.nutz.ioc.val.JavaValue.get(JavaValue.java:69)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at org.nutz.mvc.impl.Loadings.evalObj(Loadings.java:320)
at org.nutz.mvc.impl.processor.AbstractProcessor.evalObj(AbstractProcessor.java:48)
at org.nutz.mvc.impl.processor.AdaptorProcessor.evalHttpAdaptor(AdaptorProcessor.java:37)
at org.nutz.mvc.impl.processor.AdaptorProcessor.init(AdaptorProcessor.java:23)
at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:204)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5602)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.nutz.ioc.loader.map.MapLoader.getMap(MapLoader.java:128)
at org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:63)
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:155)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
... 40 more
2017-05-10 16:42:27,259 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:125) ERROR - Error happend during start serivce!
org.nutz.ioc.IocException: [myUpload, uploadFileContext, tmpFilePool, reportTempletPath, config] # For object [config] - type:[]
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:218)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at org.nutz.ioc.java.IocObjectNode.getValue(IocObjectNode.java:19)
at org.nutz.ioc.java.ChainNode.eval(ChainNode.java:24)
at org.nutz.ioc.java.ChainNode.eval(ChainNode.java:19)
at org.nutz.ioc.val.JavaValue.get(JavaValue.java:69)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.val.ReferValue.get(ReferValue.java:24)
at org.nutz.ioc.impl.ObjectMakerImpl.make(ObjectMakerImpl.java:75)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:210)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:239)
at org.nutz.mvc.impl.Loadings.evalObj(Loadings.java:320)
at org.nutz.mvc.impl.processor.AbstractProcessor.evalObj(AbstractProcessor.java:48)
at org.nutz.mvc.impl.processor.AdaptorProcessor.evalHttpAdaptor(AdaptorProcessor.java:37)
at org.nutz.mvc.impl.processor.AdaptorProcessor.init(AdaptorProcessor.java:23)
at org.nutz.mvc.impl.NutActionChainMaker.eval(NutActionChainMaker.java:38)
at org.nutz.mvc.impl.UrlMappingImpl.add(UrlMappingImpl.java:54)
at org.nutz.mvc.impl.NutLoading.evalUrlMapping(NutLoading.java:204)
at org.nutz.mvc.impl.NutLoading.load(NutLoading.java:108)
at org.nutz.mvc.ActionHandler.<init>(ActionHandler.java:19)
at org.nutz.mvc.NutFilter._init(NutFilter.java:87)
at org.nutz.mvc.NutFilter.init(NutFilter.java:65)
at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279)
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:260)
at org.apache.catalina.core.ApplicationFilterConfig.<init>(ApplicationFilterConfig.java:105)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4908)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5602)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1572)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1562)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.util.Map
at org.nutz.ioc.loader.map.MapLoader.getMap(MapLoader.java:128)
at org.nutz.ioc.loader.map.MapLoader.load(MapLoader.java:63)
at org.nutz.ioc.loader.combo.ComboIocLoader.load(ComboIocLoader.java:155)
at org.nutz.ioc.impl.NutIoc.get(NutIoc.java:180)
... 40 more
2017-05-10 16:42:27,259 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:127) ERROR - try to depose ioc
2017-05-10 16:42:27,261 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:255) INFO - org.nutz.ioc.impl.NutIoc@1559889972 is closing. startup date [17-05-10 16:42:27.136]
2017-05-10 16:42:27,261 org.nutz.ioc.impl.ScopeContext.clear(ScopeContext.java:108) DEBUG - Depose object '$aop_async' ...
2017-05-10 16:42:27,262 org.nutz.ioc.impl.NutIoc.depose(NutIoc.java:262) INFO - org.nutz.ioc.impl.NutIoc@1559889972 is deposed. startup date [17-05-10 16:42:27.136]
config的定义有问题. 另外, 为啥把config写在这里呢??? 一般是写到dao.js里面的
config : {
type : "org.nutz.ioc.impl.PropertiesProxy",
fields : {
paths : ["conf/custom/db.properties"]
},
}
添加回复
请先登陆