formPanel中设置fileupload:true后无法获取表单数据 如题,上网查了一天没找到解决办法,哪位老大帮帮忙啊 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <%@ page language="java" pageEncoding="utf-8"%><html> <head> <title>fileupload</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <%@ include file="/templates/header/ext.jsp"%> <script type="text/javascript">Ext.onReady(function() { Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8'; var form = new Ext.form.FormPanel({ renderTo : 'file', labelAlign : 'right', title : 'fileupload', labelWidth : 70, frame : true, url : '../../add_swxx.do?action=save',// fileUploadServlet width : 380, height : 200, fileUpload : true, items : [{ xtype : 'textfield', fieldLabel : 'file', name : 'file', inputType : 'file' }, { xtype : 'textfield', fieldLabel : 'file1', name : 'file1', inputType : 'file' }, { xtype : 'textfield', fieldLabel : 'file2', name : 'file2', inputType : 'file' },{ xtype : "textfield", fieldLabel : 're', id : "re", allowBlank : true, anchor : "96%" }], buttons : [{ text : 'upload', handler : function() { Ext.MessageBox.show({ title : 'Please wait', msg : 'Uploading...', progressText : '', width : 300, progress : true, closable : false, animEl : 'loding' }); form.getForm().submit({ success : function(form, action) { Ext.Msg.alert('Tip', action.result.msg); }, failure : function() { Ext.Msg.alert('Error', 'fail to upload'); }, waitMsg : 'uploading...' }); } }] });}); </script> </head> <body> <DIV id=file> </body></html></DIV> java 代码String saveDirectory = "/home/caterpillar/files/"; // 限制上传之文件大小为 5 MB int maxPostSize = 5 * 1024 * 1024 ; MultipartRequest multi = new MultipartRequest(request ,saveDirectory , maxPostSize, "UTF-8");Enumeration filenames = multi.getFileNames(); while(filenames.hasMoreElements()) { String filename = (String) filenames.nextElement(); out.println("上传了文件" + filename + "<br>"); } 问题解决:上传文件组件用jspSmartUpload.jar,这个网上可以下载我的前台代码,表单提交部分: function submit() {// if (!upfile_form.getForm().isValid()) return; upfile_form.getForm().submit({ waitMsg: '正在提交数据', waitTitle: '提示', url:'/upfileExt/servlet/upfileServlet',// fileUpload:true, method: 'post', success: function(re,v) { var jsonobject = Ext.util.JSON.decode(v.response.responseText);//将返回的JSON数据转换成JSON对象,转换失败即报错. Ext.Msg.alert("msg,oject",jsonobject.msg); // Ext.Msg.alert('提示', '保存成功'); }, failure: function(re,v) { Ext.Msg.alert('提示', '上传失败'); } }); } 这是我的部分后台代码:public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //获取各个变量的值 FileUploadPO fup=new FileUploadPO(); //上传文件 SmartUpload upload=new SmartUpload(); //初始化对象 upload.initialize(this.getServletConfig(), request, response); //限制总上传数据的长度:字节,K,M upload.setTotalMaxFileSize(1024*1024*50); try { Date now = new Date(); upload.initialize(this.getServletConfig(), request, response); upload.upload(); com.jspsmart.upload.Request rq = upload.getRequest(); String paperTitle = rq.getParameter("paperTitle");//paperTitle对应的前台界面是:{type:textfield,fieldLabel:'文章标题',name:'paperTitle',id:'paperTitle'} 求一段js更改文本中连接参数 jquery能不能在chrome自带的开发工具测试 【关于https】100分求解一个问题 如何用JS来判断浏览器是否可以播放视频? 图片上传预览问题 东西可以运行,但是提示参数无效。 ExtJS动态发送参数 诚邀各路WEB高手,打造完美虚拟城市 javascript的xmlhttp的问题,高手指教。 easy ui给元素增加属性 jquery-ui-1.8.16.custom 里面的demo在FF 和chrome里面怎么看不到效果? JS表单验证IE通过,在Firefox Opera下运行有误!
<head>
<title>fileupload</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<%@ include file="/templates/header/ext.jsp"%>
<script type="text/javascript">
Ext.onReady(function() {
Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';
var form = new Ext.form.FormPanel({
renderTo : 'file',
labelAlign : 'right',
title : 'fileupload',
labelWidth : 70,
frame : true,
url : '../../add_swxx.do?action=save',// fileUploadServlet
width : 380,
height : 200,
fileUpload : true,
items : [{
xtype : 'textfield',
fieldLabel : 'file',
name : 'file',
inputType : 'file'
}, {
xtype : 'textfield',
fieldLabel : 'file1',
name : 'file1',
inputType : 'file'
}, {
xtype : 'textfield',
fieldLabel : 'file2',
name : 'file2',
inputType : 'file'
},{
xtype : "textfield",
fieldLabel : 're',
id : "re",
allowBlank : true,
anchor : "96%"
}], buttons : [{
text : 'upload',
handler : function() {
Ext.MessageBox.show({
title : 'Please wait',
msg : 'Uploading...',
progressText : '',
width : 300,
progress : true,
closable : false,
animEl : 'loding' });
form.getForm().submit({
success : function(form, action) {
Ext.Msg.alert('Tip', action.result.msg);
},
failure : function() {
Ext.Msg.alert('Error', 'fail to upload');
},
waitMsg : 'uploading...' });
}
}]
});});
</script>
</head>
<body>
<DIV id=file>
</body>
</html></DIV>
String saveDirectory = "/home/caterpillar/files/";
// 限制上传之文件大小为 5 MB
int maxPostSize = 5 * 1024 * 1024 ;
MultipartRequest multi = new MultipartRequest(request ,saveDirectory , maxPostSize, "UTF-8");Enumeration filenames = multi.getFileNames();
while(filenames.hasMoreElements()) {
String filename = (String) filenames.nextElement();
out.println("上传了文件" + filename + "<br>");
}
我的前台代码,表单提交部分: function submit() {
// if (!upfile_form.getForm().isValid()) return;
upfile_form.getForm().submit({
waitMsg: '正在提交数据',
waitTitle: '提示',
url:'/upfileExt/servlet/upfileServlet',
// fileUpload:true,
method: 'post',
success: function(re,v) {
var jsonobject = Ext.util.JSON.decode(v.response.responseText);//将返回的JSON数据转换成JSON对象,转换失败即报错.
Ext.Msg.alert("msg,oject",jsonobject.msg);
// Ext.Msg.alert('提示', '保存成功');
},
failure: function(re,v) {
Ext.Msg.alert('提示', '上传失败');
}
});
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
//获取各个变量的值
FileUploadPO fup=new FileUploadPO();
//上传文件
SmartUpload upload=new SmartUpload();
//初始化对象
upload.initialize(this.getServletConfig(), request, response);
//限制总上传数据的长度:字节,K,M
upload.setTotalMaxFileSize(1024*1024*50);
try {
Date now = new Date();
upload.initialize(this.getServletConfig(), request, response);
upload.upload();
com.jspsmart.upload.Request rq = upload.getRequest();
String paperTitle = rq.getParameter("paperTitle");//paperTitle对应的前台界面是:{type:textfield,fieldLabel:'文章标题',name:'paperTitle',id:'paperTitle'}