- 浏览: 2990806 次
- 性别:
- 来自: 河南
文章分类
- 全部博客 (340)
- Java综合 (26)
- 程序人生 (53)
- RIA-ExtJS专栏 (18)
- RIA-mxGraph专栏 (4)
- RIA-Flex4专栏 (43)
- 框架-Spring专栏 (16)
- 框架-持久化专栏 (22)
- 框架-Struts2专栏 (11)
- 框架-Struts专栏 (12)
- SQL/NOSQL (12)
- 报表/图表 (2)
- 工作流 (5)
- XML专栏 (4)
- 日常报错解决方案 (5)
- Web前端-综合 (12)
- Web/JSP (14)
- Web前端-ajax专栏 (14)
- Web前端-JQuery专栏 (9)
- IDE技巧 (6)
- FILE/IO (14)
- 远程服务调用 (2)
- SSO单点登录 (2)
- 资源分享 (22)
- 云计算 (1)
- 项目管理 (3)
- php专栏 (1)
- Python专栏 (2)
- Linux (1)
- 缓存系统 (1)
- 队列服务器 (1)
- 网络编程 (0)
- Node.js (1)
最新评论
-
hui1989106a:
我的也不能解压,360和好压都试了,都不行
《Spring in Action》完整中文版分享下载 -
temotemo:
这些example有些过时了,官方建议使用HBase-1.0 ...
Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询 -
zy8102:
非常感谢~
HeadFirst系列之七:《深入浅出SQL》原版高清PDF电子书分享下载 -
zy8102:
重命名了一下搞定了
HeadFirst系列之七:《深入浅出SQL》原版高清PDF电子书分享下载 -
zy8102:
为什么下载以后老解压不了呢?
HeadFirst系列之七:《深入浅出SQL》原版高清PDF电子书分享下载
今天突然想起来以前的关于EXT的上传的文章没有贴出来,现在贴出代码在此
var uploadForm= new Ext.FormPanel({
id: 'form-panel',
fileUpload: true,
width: 500,
frame: true,
//title: '流程文件上传',
collapsible:true,
autoHeight: true,
bodyStyle: 'padding: 10px 10px 0 10px;',
labelWidth: 50,
defaults: {
anchor: '95%',
allowBlank: false,
msgTarget: 'side'
},
items: [{
xtype:'combo',
width : 200,
allowBlank : false,
blankText : '必须选择文档类型',
hiddenName : 'CId', //这个hiddenName指的就是BookTypeId
name : 'CName',
store : new Ext.data.Store({
autoLoad :true,
reader: new Ext.data.JsonReader({//读取json数据
root:'TCategoryList', //
totalProperty:'totalProperty', //总记录数
id:'CId'
},
Ext.data.Record.create([
{name: 'CId'},
{name: 'CName'}
])
),
proxy : new Ext.data.HttpProxy({
url : path+'doc/getTCategoryForDoc.action'
})
}),//设置数据源
allQuery:'alldoc',//查询全部信息的查询字符串
triggerAction: 'all',//单击触发按钮显示全部数据
editable : false,//禁止编辑
loadingText : '正在加载文档类型信息',//加载数据时显示的提示信息
displayField:'CName',//定义要显示的字段
valueField : 'CId',
emptyText :'请选择文档类型',
mode: 'remote',//远程模式
id:'CName',
fieldLabel:'类型'
},{
xtype: 'fileuploadfield',
id: 'form-file',
emptyText: '请选择流程文件...',
fieldLabel: '文件',
name: 'upload', // ★ from字段,对应后台java的bean属性,上传的文件字段
buttonCfg: {
text: '', // 上传文件时的本地查找按钮
iconCls: 'icon-upload' // 按钮上的图片,定义在CSS中
}
},
{
xtype: 'hidden',
id: 'fileName',
emptyText: '请选择文档文件...',
name: 'fileName',
text:Ext.getCmp("form-file") //在上传这个框中,getCmp可以获取整条路径的最后的名称
},
{
xtype:'hidden',
name : 'docId',
id:'docId'
}
],
buttons: [{
text: '上传',
handler: function(){
if(uploadForm.getForm().isValid()){
uploadForm.getForm().submit({
url:path+ 'upload/upload.action?Tab_staffId='+staffId,
method:'POST',
waitTitle: '请稍后',
waitMsg: '正在上传文档文件 ...',
success: function(fp, action){
updatedocListForUpload(action.result.docId,action.result.name,action.result.docUrl,action.result.CName,action.result.extType,action.result.state);
msg('成功!', '文档文件上传成功!');
//msg("返回的ID呢"+action.result.docId);
//Ext.log('上传成功。')
//Ext.log(action.failure)
//failure
//Ext.log(action.result.upload);
//Ext.log(action.result.msg);
Ext.getCmp("form-file").reset(); // 指定文件字段的id清空其内容
Ext.getCmp("CName").reset();
},
failure: function(fp, action){
msg('失败!', '文档文件上传失败!');
}
});
}
}
},{
text: '重置',
handler: function(){
uploadForm.getForm().reset();
}
}]
});
具体处理的ACTION
package lsbpm.web.action;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URLEncoder;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
import lsbpm.db.domain2.TCategory;
import lsbpm.db.domain2.TDoc;
import lsbpm.db.domain2.TDocCategory;
import lsbpm.db.domain2.TStaff;
import lsbpm.web.lecene.LuceneIndex;
import net.sf.json.JSONObject;
import org.apache.struts2.ServletActionContext;
/**
* Show case File Upload example's action. <code>FileUploadAction</code>
*/
public class FileUploadAction extends BaseAction {
private static final long serialVersionUID = 5156288255337069381L;
private String contentType;
private File upload;
private String fileName;
private String caption;
private String CId;//文档TCategory的ID
private String jsonMsg;// 返回ExtJs upload form消息
private String Tab_staffId;
public String getJsonMsg() {
return jsonMsg;
}
public void setJsonMsg(String jsonMsg) {
this.jsonMsg = jsonMsg;
}
// since we are using <s:file name="upload" .../> the file name will be
// obtained through getter/setter of <file-tag-name>FileName
public String getUploadFileName() {
return fileName;
}
public void setUploadFileName(String fileName) {
this.fileName = fileName;
}
// since we are using <s:file name="upload" ... /> the content type will be
// obtained through getter/setter of <file-tag-name>ContentType
public String getUploadContentType() {
return contentType;
}
public void setUploadContentType(String contentType) {
this.contentType = contentType;
}
// since we are using <s:file name="upload" ... /> the File itself will be
// obtained through getter/setter of <file-tag-name>
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getCaption() {
return caption;
}
public void setCaption(String caption) {
this.caption = caption;
}
// 解析上传的流程文件,将流程图分解后存入数据库中
// 用json格式返回成功失败及错误信息等,可直接与ExtJS衔接。
public String combinStr(String str,int i){
str=str.substring(0,str.indexOf("."))+i+ str.substring(str.indexOf("."));
return str;
}
public String upload() throws Exception {
System.out.println("执行上传文件操作。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。");
// 定义要返回的对象,返回时用json包装
HashMap<String, String> retMsg = new HashMap<String, String>();
TStaff staff=(TStaff)genericService.findById(TStaff.class, Tab_staffId);
TCategory category=(TCategory)genericService.findById(TCategory.class, CId);
TDoc doc = new TDoc();
doc.setName(fileName);//-------------------------------------------------(1)filename属性(非空)
System.out.println("拼装前------------------>"+fileName);
List<String> propertisList=new ArrayList<String>();
propertisList.add("docVersion-");
List<TDoc> result=genericService.findByProperty(doc, propertisList, 0, 0);
doc.setDocVersion(1);//-------------------------------------------------(2)DocVersion属性(非空)
int size=propertisList==null?0:result.size();
if(size>0){
int docVersion=result.get(0).getDocVersion();
doc.setDocVersion(docVersion+1);
fileName=combinStr(fileName,docVersion+1);////主要针对相同名称的文件处理加上版本号
System.out.println("--------------------经过版本升级---------------------------------");
}
doc.setDocAlias(fileName);//-------------------------------------------------(3)DocAlias属性(非空)
doc.setBoost(0d);//-------------------------------------------------(4)Broost属性(非空)
System.out.println("拼装后----------------->"+fileName);
String realPath="E:\\DataDir\\"+fileName;
if (upload.isFile()) {
BufferedInputStream bis = new BufferedInputStream(
new FileInputStream(upload));
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(new FileOutputStream(realPath));//为以防万一,以后写文件的路径尽量写成正双斜杠的
// 从源文件中取数据,写到目标文件中
byte[] buff = new byte[8192];
for (int len = -1; (len = bis.read(buff)) != -1;) {
bos.write(buff, 0, len);
}
bos.flush();
} catch (IOException ie) {
ie.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
if (bos != null) {
try {
bos.close();
} catch (IOException ie) {
ie.printStackTrace();
}
}
}
System.out.println("----------------------------0000");
doc.setDocUrl(fileName);//-------------------------------------------------(5)DocUrl属性(非空)
doc.setExtType(fileName.substring(fileName.lastIndexOf('.')+1));//---------(6)extType属性(非空)
doc.setState("可用");//状态这个暂时写死为可用 //----------------------------------(7)state属性(非空)
doc.setTStaffByDesigner(staff);//设计者先和操作者暂定为同一人-------------------- (8)designer属性(可空)
doc.setTStaffByOperator(staff);//------------------------------------------(9)operator属性(非空)
doc.setUpgradeDate(new Timestamp(System.currentTimeMillis()));
boolean isSuccess = false;
System.out.println("即将要插入数据库的文件内容为:"+doc);
genericService.create(doc);
//插入文档类型
TDocCategory cate=new TDocCategory();
cate.setTCategory(category);
cate.setTDoc(doc);
cate.setBoost(0d);
genericService.create(cate);
String Id = doc.getDocId();
System.out.println("新增后获取到的员工ID" + Id);
System.out.println(fileName + "----------------");
String extTypes=doc.getExtType();
//如果上传的文件在我要建立索引的范围之内,可以见索引,否则不建立
if(extTypes.equals("pdf")||extTypes.equals("html")||
extTypes.equals("rtf")||extTypes.equals("doc")||
extTypes.equals("ppt")||extTypes.equals("xls")||
extTypes.equals("txt")){
LuceneIndex index=new LuceneIndex();//建立索引
index.buildsingle(doc);
System.out.println("索引完毕。。。。。。。。。。。。。。。。。。。。。");
}
// 流程文件解析和加载,成功! 将流打到客户端
retMsg.put("success", "true");
retMsg.put("docId", Id);
retMsg.put("name", doc.getDocAlias());
if(doc.getTDocCategories().size()==1){
for(TDocCategory cate1:doc.getTDocCategories()){
retMsg.put("CName",cate1.getTCategory().getName());
}
}
retMsg.put("extType", doc.getExtType());
retMsg.put("state", doc.getState());
retMsg.put("docId", doc.getDocId());
retMsg.put("docUrl", doc.getDocUrl());
retMsg.put("upload", "ok");
retMsg.put("msg", "hhaahhaa!!");
} else {
// 流程文件解析和加载,失败!
retMsg.put("failure", "true");
retMsg.put("upload", "error");
retMsg.put("msg", " failed !!");
}
// json包装返回对象
jsonMsg = JSONObject.fromObject(retMsg).toString();
return SUCCESS;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public String getCId() {
return CId;
}
public void setCId(String cId) {
CId = cId;
}
public String getTab_staffId() {
return Tab_staffId;
}
public void setTab_staffId(String tabStaffId) {
Tab_staffId = tabStaffId;
}
}
struts.xml中添加一行代码
<!-- 该属性指定Struts 2文件上传中整个请求内容允许的最大字节数 -->
<constant name="struts.multipart.maxSize" value="102400000000000" />
评论
5 楼
zhaoluck
2013-08-05
急求 为啥我的上传有时候成功有时候失败呢?contentType 在strust2 里有配置吗?
4 楼
pintnotice
2011-12-28
还需要这几个文件.
17.import lsbpm.db.domain2.TCategory;
18.import lsbpm.db.domain2.TDoc;
19.import lsbpm.db.domain2.TDocCategory;
20.import lsbpm.db.domain2.TStaff;
21.import lsbpm.web.lecene.LuceneIndex;
17.import lsbpm.db.domain2.TCategory;
18.import lsbpm.db.domain2.TDoc;
19.import lsbpm.db.domain2.TDocCategory;
20.import lsbpm.db.domain2.TStaff;
21.import lsbpm.web.lecene.LuceneIndex;
3 楼
gostseraph
2010-09-28
请问你的ACTION返回的是JSON吗 ?
为什么我上传后,返回的JSON数据,提示下载呢 ?
为什么我上传后,返回的JSON数据,提示下载呢 ?
2 楼
JavaCrazyer
2010-07-26
xff 写道
咦,为了extjs+strust2文件上传上网搜到lz的文章,却不想楼主原来也对《弟子规》有研究?
呵呵,本人十分欣赏我国的古典文化作品,弟子规堪称经典,想必每个人都会有所了解吧
1 楼
xff
2010-07-24
咦,为了extjs+strust2文件上传上网搜到lz的文章,却不想楼主原来也对《弟子规》有研究?
发表评论
-
ExtTree之右键菜单增删改及拖拽同步数据库
2010-05-06 23:42 6902单凭一个ExtTree也要学习 ... -
Ext各种开发示例下载
2010-05-02 18:27 2894刚浏览网页时,无意间看到一位仁兄辛苦搜集的好多Ext的demo ... -
Ext之Tree与Tab组合问题
2010-04-30 12:36 3453ExtTree与ExtTab结合的时候经常会出现点击左边Tre ... -
分享两种comboBoxTree下拉列表树的写法
2010-04-27 23:57 9609第一种方式,经过仔细拓展后的,看起来不错,其实有点毛病就是点击 ... -
推荐一位两位Ext高人的文章
2010-04-25 08:03 1653http://ext.group.iteye.com/grou ... -
带搜索的ExtGrid终于能分页了
2010-04-25 07:14 3271前天下午参照了一位网友的说法,为了显示查询后的结果采用了下面的 ... -
Ext之ExtGrid增删改查询回顾总结
2010-04-17 10:32 3959学习Ext已经有些许时间了,发现实际运用过程中ExtGrid系 ... -
Ext树图标从http://extjs.com/s.gif上自动下载新发现
2010-04-13 17:09 4658关于EXT树图标自动下载,我又发现了一点问题,我分几种情况说下 ... -
ExtJS之Ext.Ajax.request用法详解
2010-04-11 11:41 102426Ext.Ajax.request({ ... -
ExtJS之实现华丽的皮肤主题更换
2010-04-10 23:24 22276extjs的默认皮肤很好看,但是我们还可以变换样式切换其他皮肤 ... -
ExtJS嵌入网页要解决iframe自动适应窗体大小的问题
2010-04-09 19:10 9468最近在ExtJS开发中用到了iframe标签在TabPane ... -
ExtJS使用技巧小结
2010-04-08 23:47 2859第一点:更换ExtTree ... -
ExtJS之修改编辑时的表单加载
2010-04-06 20:16 5692Ext表单加载通常是这么写的 bookForm.f ... -
ExtJS之调试功能,特棒
2010-04-06 19:10 7089在ExtJS开发过程中,经常会遇到怎么也找不到错误 ... -
ExtJS之GridPanel分页原理解读
2010-04-05 12:19 7430一般在JS代码中这样设定store.load({para ... -
ExtJS小试牛刀之表单验证
2010-04-03 15:12 3715对ExtJS基础稍微有所了解的人都知道,表单验证 ... -
使用ExtJS之Grid有感而发,贡献示例给大家
2010-03-17 17:18 3521最近研究ExtJs觉得官方示例代码有些过多,尤其是Gri ...
相关推荐
Extjs4文件上传,后台struts2
网上有些这样的例子,但是下了几个都没有跑起来,哎,希望那些发文章的人要发就发全的,别发个半生不熟的。... 现在自己整理了一个Struts2+ExtJS2实现文异步文件上传,没法上传图片无法看到效果,直接上源码吧。
研究了半天的ExtJs+Struts2多文件上传.直接导入就可以运行。
Extjs Tree + JSON + Struts2 示例源代码
struts2+extjs3的单/多文件上传,后台也可以不用struts2,前台也可以去掉extjs,资源包含所需要的所有JAR包,无需另外下载,代码量绝对精简易懂。
extjs tree + json+struts2示例源代码extjs tree + json+struts2示例源代码
Extjs的配置文件,直接将其复制到项目中即可,并附上示例JSP和js程序文件,简单易用,方便学习
eclipse下EXTJS4+STRUTS2+JAVA增删改查的完整例子
1.extjs 的简单增删改。 2.后台使用struts2实现 3.左边是树形菜单。
应用extjs4和struts2开发的省市区三级联动完整示例,导入myeclipse即可用,无需再导入任何jar包
EXTJS 折线 chart action 代码示例 1.远程加载数据(两种方法) 2.本地加载数据 3.完整示例,实例 4.后台为JAVA代码
EXTJS 上传组件及示例EXTJS 上传组件及示例EXTJS 上传组件及示例
Extjs6 最简单的示例java版Extjs6 最简单的示例java版Extjs6 最简单的示例java版Extjs6 最简单的示例java版Extjs6 最简单的示例java版Extjs6 最简单的示例java版
extjs Struts 实例程序 示例 extjs2 extjs+struts+mysql 示例程序
ExtJs + Struts2 + JSON 程序总结
Struts2、Spring、Hibernate整合ExtJS
iterator_jsonDemo1的链接:http://download.csdn.net/detail/cafebar123/8816409 运用了Extjs,Struts2, json,iterator技术, 将数据从后台传到Extjs表现层(自带json相关jar包)。注释详细,供参考。 Use ...
struts2+extjs+json整合实例
Struts2与extjs整合例子