当前位置:首页 » 文件管理 » extjs上传附件

extjs上传附件

发布时间: 2022-11-27 07:34:32

⑴ extjs+jsp+SSH的文件上传功能,上传两个或多个文件时怎么传参

// 用String数组来封装多个上传文件名
private String[] uploadFileName;

⑵ extjs 要在选择按钮后增加一个上传按钮,

单个按钮的话,参考如下,如果你是想通过两个按钮来表达开关稍作扩展即可:

new Ext.Button ({
scale:'Large',
fieldLabel :'是否',
iconAlign : 'left',
id : 'ynButton',
tag : 'Y',
handler :function(button){
if(button.tag == 'N'){
button.tag = 'Y';
Ext.getDom(button.getId()).innerHTML ='Y图片';
}else if(button.tag=='Y'){
button.tag= 'N';
Ext.getDom(button.getId()).innerHTML ='N图片';
}
}
})

⑶ EXTJS控件的附件上传,json解析

前台循环出来只有1条,要搞清楚为什么?

理论上,如果a类型有相同类型的3条数据,每条数据里有1个附件。

那么3条数据的字段(id、存放附件)的值应该都不一样,而字段类型的值一样(都是a类型)。

那么要看你的JSON,是按照类型,还是按照ID为主键存取的。如果按照类型来读写,那多条相同类型的记录,能否通过数组来表达?

⑷ ExtJs中的文件上传下载功能求教,100分

http://hi..com/%B1%F9%C3%CE%CE%DE%BA%DB/blog/item/3b19542954c90ff799250a29.html

前台EXT(假设上传文件为2个):主要就是个formPanel,items中写为:

{
xtype : 'textfield',
fieldLabel : '上传文件1',
name : 'file',
inputType : 'file'
}, {
xtype : 'textfield',
fieldLabel : '上传文件2',
name : 'file',
inputType : 'file'
}

其他地方不详细诉说了,不明白看EXT表单提交去,别忘记fileUpload : true就可以了

注意:因为是用struts2处理,name都是一样的file

struts2后台:

private List<File> file;对应前面的name
// 使用列表保存多个上传文件的文件名
private List<String> fileFileName;
// 使用列表保存多个上传文件的MIME类型
private List<String> fileContentType;
// 保存上传文件的目录,相对于Web应用程序的根路径,在struts.xml文件中配置
private String uploadDir;

get/set方法略

public void fileUpLoad() {
String newFileName = null;
BufferedOutputStream bos = null;
BufferedInputStream bis = null;
String reInfo="";//上传成功返回的东西
for (int i = 0; i < file.size(); i++) {
long now = new Date().getTime();
int index = fileFileName.get(i).lastIndexOf('.');
String path = ServletActionContext.getServletContext().getRealPath(
uploadDir);
File dir = new File(path);
if (!dir.exists())
dir.mkdir();//创建个文件夹
if (index != -1)
newFileName = fileFileName.get(i).substring(0, index) + "-"
+ now + fileFileName.get(i).substring(index);//生成新文件名
else
newFileName = fileFileName.get(i) + "-" + now;
reInfo+=newFileName+"@";
bos = null;
bis = null;
try {
FileInputStream fis = new FileInputStream(file.get(i)); // /////////
bis = new BufferedInputStream(fis);
FileOutputStream fos = new FileOutputStream(new File(dir,
newFileName));
bos = new BufferedOutputStream(fos);
byte[] buf = new byte[4096];
int len = -1;
while ((len = bis.read(buf)) != -1) {
bos.write(buf, 0, len);
}
} catch (Exception e) {
/////错误返回
try {
HttpServletResponse response = ApplicationWebRequestContext
.getWebApplicationContext().getResponse();
String msg = "{success:false,errors:{name:'上传错误'}}";
response.getWriter().write(msg);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
////////
} finally {
////////////////////////善后
try {
if (null != bis)
bis.close();
} catch (IOException e) {
e.printStackTrace();
}

try {
if (null != bos)
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
////////////////////////////////
}

//最后若没错误返回就这里返回了
try {
HttpServletResponse response = ApplicationWebRequestContext
.getWebApplicationContext().getResponse();
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
String msg = "{success:true,msg:'"+reInfo+"'}";
response.getWriter().write(msg);

} catch (Exception e) {
e.printStackTrace();
}
}
改方法参考了孙鑫的strut2深入详解,自己修改而成

注意上面2个黑体,尤其是第2行,不加的话浏览器会很悲剧的再你上传陈宫以后的返回前后加上<pre>,于是ext表单获得返回失败,这就是为什么有些人用其他EXT上传组件时候上传成功一直卡成进度条那

⑸ extjs 如何在动态生成的EditorGridPanel的单元格里面添加一个上传文件的功能

容器(可以是form等等).GetItemText("列名")
获取到你附件列
然后SetItemText("列名",设置的值)
也可以用
控件类.SetItemValue(设置的值)

⑹ extjs怎样做图片上传

ExtJS有附件上传组件的!建议楼主看一下ExtJS原生的demo和API

⑺ Extjs怎么上传文件,后台是在服务器端执行的

上传的文件是本地的啊,怎么会是服务器上的呢。

⑻ extjs 3.4中 怎么给htmlEdit添加图片插件 实现图片上传功能

首先要使用extjs自带的HTMLEditor,然后在原有的工具条上添加一个图片按钮,点击这个图片按钮要弹出窗口,这个窗口负责实现上传功能,实现上传后,要将上传的图片路径添加到HTMLEditor的光标处,并且要以<IMG></IMG>的方式,这样HTMLEditor才能解析出来。实现代码如下:

前台JSP页面



fieldLabel : '商品特性',
id : 'shopSp.spTxms',

name : 'shopSp.spTxms',
xtype : 'StarHtmleditor',
anchor : '93%'


这其中引用了StarHtmleditor,StarHtmleditor.js的代码如下,直接将代码复制下来,然后新建个JS,全复制进去就行了。


var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, {
addImage : function() {
var editor = this;
var imgform = new Ext.FormPanel({
region : 'center',
labelWidth : 55,
frame : true,
bodyStyle : 'padding:5px 5px 0',
autoScroll : true,
border : false,
fileUpload : true,
items : [{
xtype : 'textfield',
fieldLabel : '选择文件',
id : 'UserFile',
name : 'UserFile',
inputType : 'file',
allowBlank : false,
blankText : '文件不能为空',
anchor : '90%'
}],
buttons : [{
text : '上传',
handler : function() {
if (!imgform.form.isValid()) {return;}
imgform.form.submit({
waitMsg : '正在上传......',
url : 'HTMLEditorAddImgCommonAction.action',
success : function(form, action) {
var element = document.createElement("img");
element.src = action.result.fileURL;
if (Ext.isIE) {
editor.insertAtCursor(element.outerHTML);
} else {
var selection = editor.win.getSelection();
if (!selection.isCollapsed) {
selection.deleteFromDocument();
}
selection.getRangeAt(0).insertNode(element);
}
//win.hide();//原始方法,但只能传一个图片
//更新后的方法
form.reset();
win.close();
},
failure : function(form, action) {
form.reset();
if (action.failureType == Ext.form.Action.SERVER_INVALID)
Ext.MessageBox.alert('警告','上传失败',action.result.errors.msg);
}
});
}
}, {
text : '关闭',
handler : function() {
win.close(this);
}
}]
})

var win = new Ext.Window({
title : "上传图片",
width : 300,
height : 200,
modal : true,
border : false,
iconCls : "picture.png",
layout : "fit",
items : imgform

});
win.show();
},
createToolbar : function(editor) {
HTMLEditor.superclass.createToolbar.call(this, editor);
this.tb.insertButton(16, {
cls : "x-btn-icon",
icon : "picture.png",
handler : this.addImage,
scope : this
});
}
});
Ext.reg('StarHtmleditor', HTMLEditor);

JS的第一句var HTMLEditor = Ext.extend(Ext.form.HtmlEditor, 网上是没有var的,不用var不知道为什么总是报错,另外JS一定要与JSP的编码方式一致,要不然报莫名其妙的错误,而且错误都没有显示。

后台java代码



/****
* HTMLEditor增加上传图片功能:
* 1、上传图片后,需要将图片的位置及图片的名称返回给前台HTMLEditor
* 2、前台HTMLEditor根据返回的值将图片显示出来
* 3、进行统一保存
* @param 上传图片功能
* @return JSON结果
* @throws IOException
*/
public void HTMLEditorAddImg() throws IOException {
if(!"".equals(UserFile) && UserFile != null && UserFile.length() > 0){
File path = ImportImg(UserFile, "jpg");
UserFilePath = "../" + path.toString().replaceAll("\\", "/").substring(path.toString().replaceAll("\\", "/").indexOf("FileImg"));
}
this.getResponse().setContentType("text/html");
this.getResponse().getWriter().write("{success:'true',fileURL:'" + UserFilePath + "'}");
}


特别要注意的是路径问题,路径问题主要有2点需要注意:

1、前台页面引用StarHtmleditor.js的路径一定要正确;

2、Htmleditor上传的图片路径一定要改,因为上传之后图片路径变为http://localhost:8080/,在正常使用中图片不显示,要将该地址替换为服务器的IP地址;替换方法如下:


//获取本地IP地址,因为extjs的htmleditor上传的照片路径有问题,需要将路径替换为本机IP地址
InetAddress inet = InetAddress.getLocalHost();
shopSp.setSpTxms(shopSp.getSpTxms().replace("localhost", inet.getHostAddress().toString()));

这样基本就完成了这个HTMLEditor上传图片功能。

如图:

⑼ ExtJs可以限制上传文件的格式吗

ExtJs能不能不知道(貌似不可以),但是可以用别的方式达到。给你提供个思路:比如你限制仅能上传txt,pdf,xml,doc格式的文件,上传时,先获取上传的文件名,截取文件的后缀名(这个很简单,用split功能就可以了,以 .(点)作为分隔符),然后跟允许的上传格式字符对比,如果不同,则不允许上传,相同则允许(其实用正则表达式也是可以的)。比如:
var a="filename.pdf"(文件名自己去获取)
var b=a.split(".")(截取之后是个数组["filename","pdf"])
b[1]就是后缀名pdf
这样再对比:if(
b[1]
.toLowerCase()==‘pdf’)
alert("ok");

⑽ extjs ajax 可以上传文件吗

文件上传的Ajax,首先Ajax并不支持流的传输,只是在里面套了个iframe。

//ajax上传
Ext.get('btn').on('click',function(){
Ext.Ajax.request({
url:'Upload.php',
isUpload:true,
form:'upform',
success:function(){
Ext.Msg.alert('upfile','文件上传成功!');
}
});
});
<formid="upform">
请选择文件:<inputtype="file"name="imgFile"/>
<inputtype="button"id="btn"value="上传"/>
</form>
<?php
if(!isset($_FILES['imgFile'])){
echojson_encode(array("success"=>false,'msg'=>"NotgetImgfile"));
return;
}
$upfile=$_FILES['imgFile'];
$name=$upfile["name"];//上传文件的文件名
$type=$upfile["type"];//上传文件的类型
$size=$upfile["size"];//上传文件的大小
$tmp_name=$upfile["tmp_name"];//上传文件的临时存放路径
$error_cod=$upfile["error"];
if($error_cod>0){
echojson_encode(array("success"=>false,'msg'=>$error_cod));
}
$photo_tmp_file_name=//这里设置存放路径
move_uploaded_file($tmp_name,$photo_tmp_file_name);//存储文件
?>
热点内容
存储标准性 发布:2024-05-03 13:37:07 浏览:416
液碱存储 发布:2024-05-03 13:21:13 浏览:156
linux如何改配置文件 发布:2024-05-03 13:00:54 浏览:31
哪个安卓模拟器老爷机带得动 发布:2024-05-03 13:00:49 浏览:576
编程与实战 发布:2024-05-03 12:54:30 浏览:38
电脑开机有密码rpc服务器不可用 发布:2024-05-03 12:40:54 浏览:471
硬件的算法 发布:2024-05-03 12:34:28 浏览:388
支付密码为什么就六位 发布:2024-05-03 12:29:17 浏览:920
脚本找书 发布:2024-05-03 12:02:17 浏览:493
境外服务器租用怎么办 发布:2024-05-03 11:45:34 浏览:944