java ajax 上传文件后台怎么给ajax传两个参数

ajax进行前台到后台传输,传输方式为POST格式时的参数
type :&POST&,
async:false,
data : dataInfo,
timeout:300000,
contentType: &application/x-www-form-urlencoded&,
url : abc,
dataType:&json&,
success : function(response) {
error : function(XMLHttpRequest, textStatus, errorThrown, data) {
alert(&数据有误,请审核!&);
利用POST方式,对应的contentType应该为application/x-www-form-urlencoded
利用GET方式,对应的contentType应该为application/json或者text2015年2月 总版技术专家分月排行榜第二
2015年2月 Web 开发大版内专家分月排行榜第一2015年1月 Web 开发大版内专家分月排行榜第一2014年12月 Web 开发大版内专家分月排行榜第一2014年11月 Web 开发大版内专家分月排行榜第一2014年10月 Web 开发大版内专家分月排行榜第一
2016年2月 总版技术专家分月排行榜第二2014年2月 总版技术专家分月排行榜第二2013年4月 总版技术专家分月排行榜第二
2016年10月优秀小版主
2016年8月优秀小版主2016年7月优秀小版主优秀小版主2015年7月优秀小版主2015年9月优秀小版主2015年5月优秀小版主2014年11月论坛优秀版主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。本帖子已过去太久远了,不再提供回复功能。后台接收不到ajax传过来的参数 - ITeye问答
javascript代码
function replyMessage() {
var input = prompt("请输入你要回复的信息", "");
var id = $('#messageId').val();
if (input != null && input != "") {
url : 'message!sendMessage.action',
type : 'post',
input : input
async : false,
success : function(msg) {
alert("success!");
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert("error");
}
后天代码
String context = ServletActionContext.getRequest().getParameter(
"input");
搞不清楚是哪里出了问题,可以进入后台请求,但是context对象老是为null,我另外一个ajax请求代码格式还有后台取值的方式是一样的但是可以拿到值,不知道这个哪里出了问题,大家帮忙看看
问题补充:斐斐宝贝 写道如果context为空的话,那就是请求的时候,传参的问题,仔细检查一下这块。
格式很规范啊,我把input对象换成“XXX”这样也不行
问题补充:是不是
var input = prompt("请输入你要回复的信息", "");
这个有问题啊,但是我换成
$.ajax({
url : 'message!sendMessage.action',
type : 'post',
input : "shdfka"
async : false,
success : function(msg) {
alert("success!");
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert("error");
});也不行啊
拼写错误哦[color=red]date[/color]: {
input : "shdfka"
date& --&& data
如果context为空的话,那就是请求的时候,传参的问题,仔细检查一下这块。
已解决问题
未解决问题Ext.Ajax.request怎么传递对象到后台Action - ITeye问答
var cell=grid.getSelectionModel().each(function(rec){
&&&&&&&&&&&&&&&&&&&&&&&&& // var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}};
&&&&&&&&&&&&&&&&&&&&&&&&&& //var newJson=Ext.encode(Ext.decode(jsonBean));
&&&&&&&&&&&&&&&&&&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&& Ext.Ajax.request({
&&&&&&&&&&&&&&&&&&&&&&&&&& url: 'addTJdept.action',
&&&&&&&&&&&&&&&&&&&&&&&&&& method: 'POST',
&&&&&&&&&&&&&&&&&&&&&&&&
scope: this,
&&&&&&&&&&&&&&&&&&&&&&&&
params:{
&&&&&&&&&&&&&&&&&&&&&&&
&& id:rec.get('dept.id')
&&&&&&&&&&&&&&&&&&&&&&&&&&
},
&&&&&&&&&&&&&&&&&&&&&&&&
success: function(response, opts){
。。。。。。。。。。。。。
我用的是Struts2+Spring+Hibernate+Extjs
是用Extjs的EditorGridPanel进行修改,不能弹出修改窗体,就直接在表格里修改,然后点击保存提交
上面我注释掉的代码是测试用的 可以获得我选择行的任何值
不过下面的params传参 只能传个字段,不能传一个对象么?
如果用form表单的话,Struts2会自动帮我填充到对象中,
Ext.ajax.request不行么?
我的action返回的是JSON对象的,这里主要就是传个dept这个对象该怎么传到后台Action中
问题补充:7454103 写道既然是 struts2& 他会默认帮你组转这个对象的!
你可以在 action里面定义一个& dept 类型的对象!
然后在传参数的时候&
& url: 'addTJdept.action?dept.deptid=123&dept.cDept'=456',
这样传到action& 然后就可以调用 dept 这个属性了! 封装好了的! 试试看!
&action name="addTJdept" class="deptAction" method="addTJDept"&
&result type="json"&
&param name="includeProperties"&success,dept.*&/param&
&/result&
&/action&
经理让我传个实体过去如果,要把?后面的参数放到Params里该怎么写
他才会自动组装进dept?
问题补充:babydeed 写道引自官方api
Ext.Ajax.request({
url: 'foo.php',
success: someFn,
failure: otherFn,
headers: {
'my-header': 'foo'
params: { foo: 'bar' }//参数名foo 参数值bar
其中的params可以
var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}};
params: jsonBean 这样即可
试过了& 不行& 哎
问题补充:babydeed 写道引自官方api
Ext.Ajax.request({
url: 'foo.php',
success: someFn,
failure: otherFn,
headers: {
'my-header': 'foo'
params: { foo: 'bar' }//参数名foo 参数值bar
其中的params可以
var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}};
params: jsonBean 这样即可
单个字段我可以传过去的
我就是想传个实体过去
字段能自动组装进dept这个实体
采纳的答案
不清楚的你的实体是什么,但是使用json对象可以的
。比如你action里有
User里有name和age
那么你就可以构造你的json
var jsonBean={'user.name':'张三','user.age':18};
然后params:jsonBean就可以了!
你直接
data:{
&&& objectName:{
&&&&& "propertityName1":"value",
&&&&& "propertityName2":"value",
& url: 'addTJdept.action?dept.deptid=123&dept.cDept'=456',
这样传到action 自动变成对象了! 赋值好了的!
然后就可以调用 dept 这个属性了!
var json= [];
json.push({
id:rec.get('dept.id'),
CDept:rec.get('dept.cDept'),
CDeptname:rec.get('dept.cDeptname'}
params: { dept: Ext.encode(json) }
后台
private S 然后set get
JSONArray jsonArray = JSONArray.fromObject(dept);
JSONObject jsonObject = jsonArray.getJSONObject(0);
jsonObject这就是你向后台传的东西 然后做的操作
var json= [];
json.push({
&& id:rec.get('dept.id'),
&& CDept:rec.get('dept.cDept'),
&& CDeptname:rec.get('dept.cDeptname'}
})
params: { dept: Ext.encode(json) }
然后后台解析!
这样应该行的
既然是 struts2& 他会默认帮你组转这个对象的!
你可以在 action里面定义一个& dept 类型的对象!
然后在传参数的时候&
& url: 'addTJdept.action?dept.deptid=123&dept.cDept'=456',
这样传到action& 然后就可以调用 dept 这个属性了! 封装好了的! 试试看!
引自官方api
Ext.Ajax.request({
url: 'foo.php',
success: someFn,
failure: otherFn,
headers: {
'my-header': 'foo'
params: { foo: 'bar' }//参数名foo 参数值bar
其中的params可以
var jsonBean={dept:{id:rec.get('dept.id'),CDept:rec.get('dept.cDept'),CDeptname:rec.get('dept.cDeptname')}};
params: jsonBean 这样即可
params的参数可以把你要传的值写成一个json对象传递的。你定义一个json对象就好了。封装你的参数
只要是json的格式的 就行
已解决问题
未解决问题}

我要回帖

更多关于 java获取ajax参数 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信