本人要实现文件的上传与下载。
在前台使用了Extjs,而action继承的是DispatchAction,
执行到这行代码:
smartupload.initialize(this.getServlet().getServletConfig(),request,response);
就出问题了。到底是什么原因?
哪位高手有相关成功的例子,麻烦提供一下,小弟拜谢了!
在前台使用了Extjs,而action继承的是DispatchAction,
执行到这行代码:
smartupload.initialize(this.getServlet().getServletConfig(),request,response);
就出问题了。到底是什么原因?
哪位高手有相关成功的例子,麻烦提供一下,小弟拜谢了!
解决方案 »
- js调用Activex控件
- struts2的标签问题
- 如何实现像论坛那样用户只能修改,删除自己发出的帖子的功能
- js可用解析java代码返回的数组吗??
- 如何使Jacorb的Name Server不生成状态文件(_nsdb_root为前缀)?
- html常识问题高分一次给帮帮我谢谢了
- getParameterMetaData 调用出错
- tomcat配置问题,为何我的Servlet和Bean不好用????
- jboss部署
- 请教javascript获取select 下拉框的值问题
- 简单问题,如何实现下拉框 的 单击事件?
- 首次接触axis webservice获得服务器端的List,有几个地方不明白,请教各位同仁……
baseCls: 'x-plain',
labelWidth: 80,
url:'courseware.do?actionType=upload_courseware',
fileUpload:true,
defaultType: 'textfield',
items: [{
xtype: 'textfield',
fieldLabel: 'File Name',
name: 'userfile',
inputType: 'file',
allowBlank: false,
blankText: 'File can\'t not empty.',
anchor: '90%' // anchor width by percentage
}, {
xtype : 'combo',
name : 'chapter',
fieldLabel : '所属章节',
width : 80,
store : new Ext.data.SimpleStore({
fields : ['chapter'],
data : [['第二章'], ['第三章'], ['第四章'], ['第五章'], ['第六章'], ['第七章'], ['第八章'], ['第九章'], ['第十章'], ['第十一章'], ['第十二章']]
}),
displayField : 'chapter',
mode : 'local',
forceSelection : true,
editable : false,
triggerAction : 'all',
value:'第一章'
}]
});
var win = new Ext.Window({
title: 'Upload file',
width: 400,
height:200,
minWidth: 300,
minHeight: 100,
layout: 'fit',
plain:true,
bodyStyle:'padding:5px;',
buttonAlign:'center',
items: form,
buttons: [{
text: 'Upload',
handler: function() {
if(form.form.isValid()){
Ext.MessageBox.show({
msg: 'Uploading...',
width:300,
progress:true,
animEl: 'loding'
});
form.getForm().submit({
success: function(form, action){
Ext.Msg.alert("系统消息", action.result.msg, function() {
this.closeWin();
courseware1Store.reload();
}, this);
},
failure: function(){
Ext.Msg.alert('Error', 'File upload failure.');
}
})
}
}
},{
text: 'Close',
handler:function(){win.hide();}
}]
});
win.show();action中的代码:public ActionForward upload_courseware(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
PrintWriter out=response.getWriter();
System.out.println(0);
SmartUpload smartupload=new SmartUpload();
System.out.println(1);
String fileName2=null;
smartupload.initialize(this.getServlet().getServletConfig(),request,response);
System.out.println(2);
try{
smartupload.setMaxFileSize(100*1024*1024);
smartupload.setAllowedFilesList("ppt,doc,xls,rar");
smartupload.upload();
System.out.println(3);
}catch(Exception ex)
{
ex.printStackTrace();
out.print("{success:false,msg:'系统异常,上传失败!'}");
return null;
}//获得上传文件个数
int filecount=smartupload.getFiles().getCount();if(filecount>0)
{
//获取上传的文件
File myFile=smartupload.getFiles().getFile(0);
//判断是否选择了文件,选择时返回false,没有选择返回true
if(!myFile.isMissing())
{
try
{
//上传文件名
String myFileName=myFile.getFileName();
String s1=smartupload.getRequest().getParameter("chapter").trim();
System.out.println(s1);
myFile.saveAs("courseware/"+myFileName, smartupload.SAVE_VIRTUAL);
}
catch(Exception e)
{
e.printStackTrace();
System.out.println(e);
}
}
}
return null;
}