当使用jquery1.3以上版本时,进行ajax参数传值时,会出现以下的一个错误:
ognl.ExpressionSyntaxException: Malformed OGNL expression: f[] [ognl.ParseException: Encountered " "]"
"] "" at line 1, column 3.
;
这个错误是因为,jquery在传递数组类参数时,将不再遵循1.3时如f=x&f=y的参数传递了,而是采用了像php一样,带中括号的参数传递。js值 {f:["x","y"]},将被转化成f[]=x&f[]=y,而这种参数形式传递到后台时,使用struts2.1.8版本时,就会出现以上的错误形式。
struts2一直能够识别的模式仅是f=x&f=y这样,当后台声明f为一个list或set时,就会把x,y分别加入到list或set中。而如果是f[]这种形式,则会报相应的转换错误。
解决此问题的方法很简单,在进行ajax请求时,追加一条以下语句即可:
$.ajaxSettings.traditional=true;
这是一个全局参数,故可以在引入jquery.js之后进行声明。此参数的意思在于,使用$.param时,将采用旧的jquery1.3版本的param生成方式进行处理。
具体的区别代码如下所示:
function buildParams( prefix, obj, traditional, add ) {
if ( jQuery.isArray( obj ) && obj.length ) {
// Serialize array item.
jQuery.each( obj, function( i, v ) {
if ( traditional || rbracket.test( prefix ) ) {
// Treat each array item as a scalar.
add( prefix, v );
} else {
// If array item is non-scalar (array or object), encode its
// numeric index to resolve deserialization ambiguity issues.
// Note that rack (as of 1.0.0) can't currently deserialize
// nested arrays properly, and attempting to do so may cause
// a server error. Possible fixes are to modify rack's
// deserialization algorithm or to provide an option or flag
// to force array serialization to be shallow.
buildParams( prefix + "[" + ( typeof v === "object" || jQuery.isArray(v) ? i : "" ) + "]", v, traditional, add );
}
});
} else if ( !traditional && obj != null && typeof obj === "object" ) {
// If we see an array here, it is empty and should be treated as an empty
// object
if ( jQuery.isArray( obj ) || jQuery.isEmptyObject( obj ) ) {
add( prefix, "" );
// Serialize object item.
} else {
for ( var name in obj ) {
buildParams( prefix + "[" + name + "]", obj[ name ], traditional, add );
}
}
} else {
// Serialize scalar item.
add( prefix, obj );
}
}
转自http://www.iflym.com/index.php/code/201110110001.html
分享到:
相关推荐
Papa Parse - Powerful CSV parser that converts CSV to JSON and JSON to CSV. Supports web workers and streaming large files. Gracefully handles malformed input. ...
使用阿里云镜像安装docker时出现如下报错,具体如下图: Malformed entry 60 in list file /etc/apt/sources.list (Component) 解决方案 注意到报错提示/etc/apt/sources.list 这个文件第60行格式错误,那么尝试...
myeclise10 svn: E210004: Number is larger than maximum 解决方案 专门解决win7 64位操作系统 下svn插件问题。 下载文件包括: site-1.8.22.zip --->svn离线安装包 Slik-Subversion-1.8.9-x64 --->问题修复必选...
主要介绍了IDEA 中使用 ECJ 编译出现 java.lang.IllegalArgumentException问题 ,本文内容简短给大家介绍的好,需要的朋友可以参考下
34.0.1 (March 2023): ...Windows: Fixed "mke2fs: Illegal or malformed device name while trying to determine filesystem size" error introduced in Platform tools 34.0.0 (issue #271039230).
Sqlite数据库报错:database disk image is malformed 按照博文的方法终于解决了我的问题: cmd切换到该目录下然后输入: sqlite3 old.db .dump > newsfeed.sql 和 sqlite3 new.db < newsfeed.sql
这是对本人同名资源的修正版,改进了其存在的问题。
resolve-package-json 解决package.json依赖版本安装 $ npm install --save resolve-package-json用法 const { resolver } = require ( 'resolve-package-json' )const pkg = require ( './package.json' )resolver ...
It is a .NET code library that allows you to parse "out of the web" HTML files. The parser is very tolerant with "real world" malformed HTML. The object model is very similar to what proposes System....
最經典的C51教程,最經典的C51教程,最經典的C51教程
AndroidGPS架构分析.pdf
今天用execjs调用JS时,发现报错execjs._exceptions.ProgramError: ReferenceError: document is not defined 如图: 错误类型:文档对象未定义,解决方法,定义对象即可,习惯性定义变量嘛 var document ;? ...
今天读了golang官方文档中的module介绍 ...从go1.11之后,Google应该是想把module变成正统包管理器了。在此,我简单的以工程角度探究一下mod。 首先,文档提到: A module is a collection of Go packages stored in a ...
以上输出显示当前已经连接了三台设备/模拟器,cf264b8f、emulator-5554 和 10.129.164.6:5555 分别是它们的 SN。从 emulator-5554 这个名字可以看出它是一个 Android 模拟器,而 10.129.164.6:5555 这种形为 <IP>:...
sqlite 出现 The database disk image is malformed问题得修复工具 使用方式 repairTool.exe 旧库的名字 新库的名字
Resolved issue 2719: When input parameter is missing or malformed, ChromeDriver response is not spec compliant [Pri-3] Resolved issue 2746: Execute Script does not handle line-oriented JavaScript ...
与西门子PLC通讯的Labview库,还不错。 以下是英文声明: Warning, the attached files are ... Needed are better error checking, cleaner S7 Response decoding, and stress testing with malformed data.
强制删除任何EXE文件和被加载的DLL文件!
Resolved issue 2719: When input parameter is missing or malformed, ChromeDriver response is not spec compliant [Pri-3] Resolved issue 2746: Execute Script does not handle line-oriented JavaScript ...