今天突然想起来以前的关于EXT的上传的文章没有贴出来,现在贴出代码在此
- <SPAN style="FONT-SIZE: medium">var uploadForm= new Ext.FormPanel({
- id: 'form-panel',
- fileUpload: true,
- width: 500,
- frame: true,
-
- 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',
- name : 'CName',
- store : new Ext.data.Store({
- autoLoad :true,
- reader: new Ext.data.JsonReader({
- 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',
- buttonCfg: {
- text: '',
- iconCls: 'icon-upload'
- }
- },
- {
- xtype: 'hidden',
- id: 'fileName',
- emptyText: '请选择文档文件...',
- name: 'fileName',
- text:Ext.getCmp("form-file")
-
- },
- {
- 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('成功!', '文档文件上传成功!');
-
-
-
-
-
-
- Ext.getCmp("form-file").reset();
- Ext.getCmp("CName").reset();
- },
- failure: function(fp, action){
- msg('失败!', '文档文件上传失败!');
- }
- });
- }
- }
- },{
- text: '重置',
- handler: function(){
- uploadForm.getForm().reset();
- }
- }]
- });</SPAN>
具体处理的ACTION
- <SPAN style="FONT-SIZE: medium">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;
-
-
-
-
- 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;
- private String jsonMsg;
- private String Tab_staffId;
- public String getJsonMsg() {
- return jsonMsg;
- }
-
- public void setJsonMsg(String jsonMsg) {
- this.jsonMsg = jsonMsg;
- }
-
-
-
- public String getUploadFileName() {
- return fileName;
- }
-
- public void setUploadFileName(String fileName) {
- this.fileName = fileName;
- }
-
-
-
- public String getUploadContentType() {
- return contentType;
- }
-
- public void setUploadContentType(String contentType) {
- this.contentType = contentType;
- }
-
-
-
- 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;
- }
-
-
-
-
- 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("执行上传文件操作。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。");
-
- 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);
- 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);
- 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);
- doc.setBoost(0d);
- 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);
- doc.setExtType(fileName.substring(fileName.lastIndexOf('.')+1));
- doc.setState("可用");
- doc.setTStaffByDesigner(staff);
- doc.setTStaffByOperator(staff);
- 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 !!");
-
- }
-
-
- 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;
- }
-
-
-
- }
- </SPAN>
struts.xml中添加一行代码
<!-- 该属性指定Struts 2文件上传中整个请求内容允许的最大字节数 -->
<constant name="struts.multipart.maxSize" value="102400000000000" />