Ready(function(){
2.
3. var form = new Ext.form.FormPanel({ inputtypefile不上传文件
4. renderTo:'file',
5. labelAlign: 'right',
6. title: '文件上传',
7. labelWidth: 60,
8. frame:true,
9. url: '../upload.do?op=uploadFile',//fileUploadServlet
10. width: 300,
11. height:200,
12. fileUpload: true,
13.
14.
15. items: [{
16. xtype: 'textfield',
17. fieldLabel: '文件名',
18. name: 'file',
19. inputType: 'file'//文件类型
20. }],
21.
22. buttons: [{
23. text: '上传',
24. handler: function() {
25. Form().submit({
26. success: function(form, action){
27. Ext.Msg.alert('信息', '文件上传成功!');
28. },
29. failure: function(){
30. Ext.Msg.alert('错误', '文件上传失败');
31. }
32. });
33. }
34. }]
35. });
36.
37. });
var form = new Ext.form.FormPanel({
renderTo:'file',
labelAlign: 'right',
title: '文件上传',
labelWidth: 60,
frame:true,
url: '../upload.do?op=uploadFile',//fileUploadServlet
width: 300,
height:200,
fileUpload: true,
items: [{
xtype: 'textfield',
fieldLabel: '文件名',
name: 'file',
inputType: 'file'//文件类型
}],
buttons: [{
text: '上传',
handler: function() {
success: function(form, action){
Ext.Msg.alert('信息', '文件上传成功!');
},
failure: function(){
Ext.Msg.alert('错误', '文件上传失败');
}
});
}
}]
});
}); 2.uploadAction.java 其中使用了cos上传组件,下载地址:www.servlets/cos/cos-05Nov2002.zip
Java代码
Java代码
1.package zx.struts.actions;
2.
3.import java.io.File;
4.import java.util.Enumeration;
5.
6.import javax.servlet.http.HttpServletRequest;
7.import javax.servlet.http.HttpServletResponse;
8.
9.import org.apache.struts.action.ActionForm;
10.import org.apache.struts.action.ActionForward;
11.import org.apache.struts.action.ActionMapping;
12.
13.illy.servlet.MultipartRequest;
14.
15.
16.public class UploadAction extends DispatchAction{
17. public ActionForward uploadFile(ActionMapping mapping, ActionForm form,
18. HttpServletRequest request, HttpServletResponse response)throws Exception {
19.
20.
21. String saveDirectory ="F:\\jboss-4.2.2.GA\\server\\default\\deploy\\userDemo.war\\upload"; //文件上
传后,保存的位置
22.
23. int maxPostSize =3 * 5 * 1024 * 1024 ; //每个文件最大5MB,最多3个文件,所以...
24.
25. //response的编码为"gb2312"
26. MultipartRequest multi =
27. new MultipartRequest(request, saveDirectory, maxPostSize,
28. "gb2312");
29.
30. //输出反馈信息
31. Enumeration files = FileNames();
32. while (files.hasMoreElements()) {
33.
34. String name = (Element();
35. File f = File(name);
36. if(f!=null){
37. String fileName = FilesystemName(name);
38. String lastFileName= saveDirectory+"\\" + fileName;
39. System.out.println("上传的文件:"+lastFileName);
40.
41.
42. }
43. }
44.
45.
46. return null;
47.}
48.}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论