菜鸟问题,EXTJS的文件类型,在后台用Request取不到值

leiaming 2009-04-02 11:01:07
代码如下:{
id : 'UploadLogo',
autoScroll : false,
xtype : 'textfield',
fieldLabel:'本地上传',
name : 'file',
hideLabel : true,
autoCreate : {
tag : "input",
type : "file",
size : "20",
autocomplete : "off",
onChange : "Ext.get('UploadLogofile').dom.value=Ext.get('file').dom.value;"
}
}

去掉type : "file", 这一行变成纯粹的文本框,就可以取到,但小弟我是做上传功能,请高手帮帮忙
...全文
1035 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
HarmonyChang 2011-06-07
  • 打赏
  • 举报
回复
学习了。
thefirstwind 2009-04-09
  • 打赏
  • 举报
回复

id : 'UploadLogo',
autoScroll : false,
xtype : 'textfield',
fieldLabel:'本地上传',
name : 'file',
hideLabel : true,
autoCreate : {
id : 'file',
tag : "input",
type : "file",
size : "20",
autocomplete : "off",
onChange : "Ext.get('UploadLogofile').dom.value=Ext.get('file').dom.value;"
}
}


加个ID试试
DWilliam 2009-04-07
  • 打赏
  • 举报
回复
Ext.onReady(function(){

Ext.QuickTips.init();

var msg = function(title, msg){
Ext.Msg.show({
title: title,
msg: msg,
minWidth: 200,
modal: true,
icon: Ext.Msg.INFO,
buttons: Ext.Msg.OK
});
};

var fibasic = new Ext.form.FileUploadField({
renderTo: 'fi-basic',
width: 400
});

new Ext.Button({
text: 'Get File Path',
renderTo: 'fi-basic-btn',
handler: function(){
var v = fibasic.getValue();
msg('Selected File', v && v != '' ? v : 'None');
}
});

var fbutton = new Ext.form.FileUploadField({
renderTo: 'fi-button',
buttonOnly: true,
listeners: {
'fileselected': function(fb, v){
var el = Ext.fly('fi-button-msg');
el.update('<b>Selected:</b> '+v);
if(!el.isVisible()){
el.slideIn('t', {
duration: .2,
easing: 'easeIn',
callback: function(){
el.highlight();
}
});
}else{
el.highlight();
}
}
}
});

var fp = new Ext.FormPanel({
renderTo: 'fi-form',
fileUpload: true,
width: 500,
frame: true,
title: 'File Upload Form',
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype: 'textfield',
fieldLabel: 'Name'
},{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: 'Select an image',
fieldLabel: 'Photo',
name: 'photo-path',
buttonCfg: {
text: '',
iconCls: 'upload-icon'
}
}],
buttons: [{
text: 'Save',
handler: function(){
if(fp.getForm().isValid()){
fp.getForm().submit({
url: 'file-upload.php',
waitMsg: 'Uploading your photo...',
success: function(fp, o){
msg('Success', 'Processed file "'+o.result.file+'" on the server');
}
});
}
}
},{
text: 'Reset',
handler: function(){
fp.getForm().reset();
}
}]
});

});
Ghost_520 2009-04-03
  • 打赏
  • 举报
回复
你要的话,我可以打包发给你一份
我的 qq:290781681
MSN:liubin5893@126.com


<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link rel="stylesheet" type="text/css" href="ext2.2/resources/css/ext-all.css" />
<link rel="stylesheet" type="text/css" href="ext2.2/examples/shared/examples.css" />
<link rel="stylesheet" type="text/css" href="upload/css/Ext.ux.UploadDialog.css" />
<script type="text/javascript" src="ext2.2/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="ext2.2/ext-all-debug.js"></script>
<script type="text/javascript" src="upload/Ext.ux.UploadDialog.packed.js"></script>
<script type="text/javascript" src="upload/Ext.ux.UploadDialog.js"></script>
</head>
<script type="text/javascript">
Ext.onReady(function() {
var dialog = new Ext.ux.UploadDialog.Dialog({
title: '文件上传__上传过程中关闭窗口,不影响上传_wayfoon',
url:'uploadJSPBack.jsp',
width : 450,
height : 300,
minWidth : 450,
minHeight : 300,
draggable : true,
resizable : true,
//autoCreate: true,
constraintoviewport: true,
permitted_extensions:['JPG','jpg','jpeg','JPEG','GIF','gif','bmp','BMP'],
modal: true,
//post_var_name: 'mms',
reset_on_hide: false,
allow_close_on_upload: true //关闭上传窗口是否仍然上传文件
// upload_autostart: false //是否自动上传文件
});

dialog.show();//'show-button'
dialog.on('uploadsuccess', onUploadSuccess);

// 上传成功后的回调成功的函数
function onUploadSuccess(dialog, filename, resp_data, record)
{
alert(filename);
}
});
</script>
<body>

</body>
</html>



<%@ page language="java"
import="java.util.*,java.io.*,org.apache.commons.fileupload.*"
pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'uploadJSPBack.jsp' starting page</title>
<meta http-equiv="Content-Type" content="text/html; charset=GBK" />

<%
response.setCharacterEncoding("GBK");
String uploadPath = "";
String tempPath = "d:\\";
try {
System.out.println("开始进行文件上传");
DiskFileUpload fu = new DiskFileUpload();
fu.setSizeMax(4194304); // 设置最大文件尺寸,这里是4MB
fu.setSizeThreshold(4096); // 设置缓冲区大小,这里是4kb
fu.setRepositoryPath(tempPath); // 设置临时目录
List fileItems = fu.parseRequest(request); // 得到所有的文件:
Iterator i = fileItems.iterator();
// 依次处理每一个文件:
while (i.hasNext()) {
FileItem fi = (FileItem) i.next();
String fileName = fi.getName();// 获得文件名,这个文件名包括路径:
if (fileName != null) {
// 在这里可以记录用户和文件信息
// 此处可以定义一个接口(CallBack),用于处理后事。
// 写入文件a.txt,你也可以从fileName中提取文件名:
String name = fileName.substring(0, fileName
.indexOf("."));
String extfile = fileName.substring(fileName
.indexOf("."));

//上传时间作为文件名,用以防止重复上传
//Timestamp now = new Timestamp((new java.util.Date()).getTime());
//SimpleDateFormat fmt = new SimpleDateFormat("yyyyMMddHHmmssSSS");
//String pfileName= fmt.format(now).toString().trim();
System.out.println(name + extfile);
fi.write(new File(name + extfile));
}
}

System.out.println("上传成功");

response.setContentType("text/html;charset=utf-8");
response.getWriter().print("{success:true,message:'上传成功'}");
// 跳转到上传成功提示页面
} catch (Exception e) {
e.printStackTrace();
response.getWriter().print("{success:false,message:'上传失败'}");
// 可以跳转出错页面
}
%>
</head>

<body>
</body>
</html>
tobyzhou 2009-04-02
  • 打赏
  • 举报
回复
如果需要带参数的话,在URL后面带上就可以了
file类型的,你在 params :{} 中传递参数,后台无法接收的。

52,798

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧