锁定老帖子 主题:ext2.0如何做文件上传?
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-07-01
能成功了 但是 后台 经常造成 session丢失
不知道为什么 |
|
返回顶楼 | |
发表时间:2008-07-14
我做了一个struts2的
但是有个问题,form.reset()方法对这个 textField无效,不能重设成空 部分核心代码如下 ...................... //图片上传 var logoUploadField = new Ext.form.TextField({ id:'logoUploadField', fieldLabel:'游戏LOGO图片', name : 'picture', anchor : '90%', height: 20, inputType:'file' } ); ................... var addForm = new Ext.FormPanel({ id:'addForm', labelAlign : 'top', frame : true, width : 500, //labelWidth : 70, url : 'test.action', fileUpload: true, items : [{ layout : 'column',// 该FormPanel的layout布局模式为列模式(column),包含2列 items : [{// 第一列 columnWidth : 0.5, layout : 'form', items : [ gamenameField,developerField,playtypeField ] }, { // 第二列 columnWidth : 0.5, layout : 'form', items : [ serialField,priceField,typeIdField ] }] },logoUploadField,introductionField], buttons : [{ text : '保存', disabled : false, handler : function() { if (addForm.form.isValid()) { addForm.form.submit({ //url : 'AddLevel.action', success : function(form, action) { form.reset(); //introductionField.setValue(""); //logoUploadField.setValue(""); Ext.MessageBox.alert('保存成功', '222222添加游戏成功!'); }, failure : function(form, action) { //introductionField.setValue(""); //logoUploadField.setValue(""); Ext.MessageBox.alert('保存失败', '添加游戏失败!'); }, waitMsg : '正在保存数据,稍后...' }); addGameFormWin.hide(); } else { Ext.Msg.alert('信息', '请填写完成再提交!'); } } }, { text : '取消', handler : function() { //addForm.getForm().reset(); addGameFormWin.hide(); } }] }); action代码如下: public class ConsoleGameAction extends ActionSupport { private String gamename; private String serial; private String developer; private String price; private String typeId; private String playtype; private String introduction; private File picture; private String pictureContentType; private String pictureFileName; private String savePath; private String jsonString; private GameService gameService; public String addGame() throws Exception{ FileOutputStream fos = new FileOutputStream(getSavePath() + "\\" + getPictureFileName()); FileInputStream fis = new FileInputStream(getPicture()); byte[] buffer = new byte[1024]; int len = 0; while((len = fis.read(buffer)) > 0){ fos.write(buffer, 0, len); } StringBuilder temp = new StringBuilder("{success:true}"); this.jsonString = temp.toString(); return SUCCESS; } public String getGamename() { return gamename; } public void setGamename(String gamename) { this.gamename = gamename; } public String getSerial() { return serial; } public void setSerial(String serial) { this.serial = serial; } public String getDeveloper() { return developer; } public void setDeveloper(String developer) { this.developer = developer; } public String getPrice() { return price; } public void setPrice(String price) { this.price = price; } public String getTypeId() { return typeId; } public void setTypeId(String typeId) { this.typeId = typeId; } public String getPlaytype() { return playtype; } public void setPlaytype(String playtype) { this.playtype = playtype; } public String getIntroduction() { return introduction; } public void setIntroduction(String introduction) { this.introduction = introduction; } public File getPicture() { return picture; } public void setPicture(File picture) { this.picture = picture; } public String getPictureContentType() { return pictureContentType; } public void setPictureContentType(String pictureContentType) { this.pictureContentType = pictureContentType; } public String getPictureFileName() { return pictureFileName; } public void setPictureFileName(String pictureFileName) { this.pictureFileName = pictureFileName; } @SuppressWarnings("deprecation") public String getSavePath() { return ServletActionContext.getRequest().getRealPath(savePath); } public void setSavePath(String savePath) { this.savePath = savePath; } public String getJsonString() { return jsonString; } public void setJsonString(String jsonString) { this.jsonString = jsonString; } public GameService getGameService() { return gameService; } public void setGameService(GameService gameService) { this.gameService = gameService; } } action配置 <action name="addgame" class="consoleGameAction" method="addGame"> <param name="savePath">/upload</param> <result name="success">/WEB-INF/console/json_data.jsp</result> </action> 哪位能帮我解决下我的问题?将file的textField设成空? setValue("")也无效 |
|
返回顶楼 | |
发表时间:2008-07-14
偶直接用smartupload,在一个总的控制器中判断有文件则保存。
然后提取request参数,并将文件保存前后的名称加到Map中, 传递到后面的business层 |
|
返回顶楼 | |