javascript 2010-08-10 19:14:44 阅读48 评论1 字号:大中小 订阅
前两天做了个ext+struts2表单上传文件的提交,提交没问题,提交后的参数返回出了问题,灰常灰常郁闷,发帖,查资料,最后成功,把一些东西总结一下,写的不好,不对,大家指正。
ext关键代码:
var addForm = new Ext.form.FormPanel(
{
id:'addForm',
baseCls: 'x-plain',
labelWidth: 75,
fileUpload: true,
method:'POST',
enctype:'multipart/form-data',
//文件上传的话要这两句
/**
*
*这里省略一些其他表单配置
*按钮配置也省略
**/
//最后服务器返回信息处理
success:function(form,action){
Ext.MessageBox.alert("Message", "Success");
},
failture:function(form,action){
Ext.MessageBox.alert("Error", "Failture");
}
如果后台有执行到,但是页面无任何反应,那肯定是action的配置出了问题。首先配置有两种,一种是继承struts-default,另外一种是json-default.
如果用struts-default,有两种方案。配置多个result
即多个html/jsp页面, <result name="sucess">/suss.html </result>,
<result name="fail">/fail.html </result>, <result name="...">/... </result>
java代码处理业务,根据异常来决定跳到哪个页面,
如写文件失败,return "writefalse";
<result name="writefalse">/writefalse.html </result>
writefalse.html的内容只能是json格式的数据,{"success:false,info:写文件失败"}
这样页面的ext就会进入
failture:function(form,action){
Ext.MessageBox.alert("Error", "Failture");
}
你在方法里取值action.result.info,内容就是 "写文件失败".
依次类推,成功页面suss.html的页面内容是{"success:true,info:成功"}
ext这个回调机制是检查返回参数是否有success键,并且它的值是true,就会调用
success:function(form,action){
},
其他{"success:false,info:asdadsad"},{"failture:true,info:asdad"}都是调用failture。即只要没有success:true,那么其他状况都将进入failtur方法。
struts-default的第二个方案是用response来传递参数。这个比较搞,resp.getWriter().write()的时候,不要忘了"[","]",不然解析不到......
错误:"{'success:true,info:asdad'}"
正确:"[{'success:true,info:asdad'}]"
另外是用jsondefault(推荐)使用,其他配置就不多说了,主要会碰到的情况,页面有响应,但是直接提示下载文件。这个时候,要在struts配置里添加一项param 把ContentType设为text/html,就不会出现下载页了。
然后用json返回的时候,也碰到了一个很搞的问题。
我们用json,一般定义一个
Map[] results =new Map[length](不要忘了get方法,不然前台取不到),
然后把我们的map元素一个个放进result里,然后返回。
但是到了表单这里,行不通,不能再返回一个Map数组,只能返回单个Map
Map results =new HashMap();
results .put("success","true");
results .put("info","sadad");
return SUCCESS;就可以了
如果
Map[] results =new HashMap[1];
Map map = new HashMap();
map.put("success","true");
map.put("info","sadad");
results[0]=map;
return SUCCESS;
这样页面就无法解析了,这里感觉有点整合的死了。
一些关键的东西,其实都能在ext的api里找到,多看api是关键。
与大家共勉,错误之处大家修正。
分享到:
相关推荐
18年7月更新,清华镜像,完美解决 Yocto,Android fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle 错误,绕开GFW
内含 ext+dwr+freemark+jasperreort+ireport+echance+oscache+velocite等技术 展示例子:http://zz563143188.iteye.com/blog/1462413 若要下载chm格式请到http://user.qzone.qq.com/563143188 程序源码下载地址10MB...
org.apache.maven.archiver.MavenArchiver.getManifest(org.apache.maven.project.MavenProject, org.apache.maven....http://repo1.maven.org/maven2/.m2e/connectors/m2eclipse-mavenarchiver/0.17.2/N/LATEST/
天气预报,城市select联动,dwr,json 全国各省名称: ...http://ext.weather.com.cn/city? 合肥 得到: http://ext.weather.com.cn/101270502.json 天气信息: http://m.weather.com.cn/data/101010100.html
(2)D:\apache2\Apache2\conf下的httpd.conf文件 第173行改为LoadModule php5_module modules/php5apache2.dll 前提是将php5apache2.dll(在D:\program files\php-5.0.0RC3-Win32下)复制到D:\apache2\Apache2\...
放大镜效果(magnifier)、阴影效果(shadow) 第一部分:鼠标交互 1.1 Draggables:拖拽所需文件: ui.mouse.js ui.draggable.js ui.draggable.ext.js 用法:文件载入后,可以拖拽class = "block"的层 $(document).ready...
$("#example").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']}); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:...
功能有:会话过滤、MD5加密、文件上传、权限设置、报表统计....... 是一个比较成熟的项目。 运行环境 jdk7+tomcat7+mysql+IntelliJ IDEA 项目技术(必填) spring+struts+hibernate 数据库文件 链接: ...
首先还是需要Tampermonkey油猴插件,...在线安装:https://ext.se.360.cn/webstore/detail/dhdgffkkebhmkfjojejmpbldmpobfkfo 然后安装网盘下载脚本,不用多,两个就够用了。 【百度网盘高速下载助手2018.04.06】 ...
$("#example").tablesorter({sortList:[[0,0],[2,1]], widgets: ['zebra']}); }); CSS文件:http://dev.jquery.com/view/trunk/themes/flora/flora.all.css 选项说明:...
1.4Ext安装 下载地址: Extjs 5 beta 版下载链接:http://cdn.sencha.com/ext/beta/ext-5.0.0.736.zip Extjs 4.2.1 下载链接:http://cdn.sencha.com/ext/gpl/ext-4.2.1-gpl.zip Extjs 4.0.7 下载链接:...
开发网站Matt Wu <mattwu>http://www.ext2fsd.com活跃的开发人员Matt Wu : http://github.com/matt-wu http://blog.dynox.cnKaHo Ng : http://github.com/ngkaho1234Ext3Fsd支持的功能1, flexible inode ...
zend_extension="D:/nServer/module/PHP5/ext3rd/eaccelerator.dll" eaccelerator.shm_size = "0" eaccelerator.cache_dir = "D:/nServer/mydata/temp/php5/eaccelerator" eaccelerator.enable = "1" eaccelerator....
1、FileUploadField 文件上传 体验例子见:http://extjs.com/deploy/dev/examples/form/file-upload.html 2、GMapPanel GMap扩展 体验例子见:http://extjs.com/deploy/dev/examples/window/gmap.html 3、...
本书共分为5个分卷,要完全下载 资料来源:大家网http://club.topsage.com 也可以去这下载完本:http://club.topsage.com/thread-2602632-1-1.html
android手机应用,企业web平台,手机端。ui用的ext,操作绚丽。
出现以下报错,替换/usr/local/include/openssl里面的文件之后编译成功。add_assoc_name_entry’:/data/src/php-5.6.23/ext/openssl/openssl.c:664: warning: ‘ASN1_STRING_data’ is deprecated (declared at /usr...
深入浅出Ext JS第2版.pdf(4/4):http://download.csdn.net/source/3554013 深入浅出Ext JS第2版.pdf(3/4):http://download.csdn.net/source/3554012 深入浅出Ext JS第2版.pdf(2/4):...
Source: http://www.cmar.csiro.au/datacentre/ext_docs/seawater.htm - the AIR-SEA-toolbox by Bob Beardlsley and Rick Pawlowicz. Source: http://woodshole.er.usgs.gov/operations/sea-mat/air_sea-html/ ...
JDK 所需jar包