实际应用
Extjs4、struts2
Extjs处理业务逻辑
struts2仅仅负责传递数据
示例:
struts2方法
public String saveIndex(){
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
String queryParam = request.getParameter("param");
oplogE.info("param:"+queryParam);
JSONObject result = SearchManager.saveIndex(queryParam);//处理数据的方法
try {
response = initHeader(response);
response.getWriter().print(result);
} catch (IOException e) {
oplogE.error("保存检索式状态:", e);
}
return null;
}
通过“response.getWriter().print(result);”向前台传递result,result是json格式,ext可通过相关操作获得所需数据
Ext接受数据方法
Ext.Ajax.request( {
url :extPath + '/search!saveIndex.action',
params : {
param:inputData
},
method :'POST',
success : function(response) {
el.unmask();
var json = Ext.JSON.decode(response.responseText); // 获得后台传递json
if(json.success){
if(json.success == true){
Ext.Msg.alert('正确','保存成功!');
}else{
alert("abc");
Ext.Msg.alert('错误','保存失败!');
}
}else{
Ext.Msg.alert('错误','保存失败!');
}
},
failure: function(){
el.unmask();
Ext.Msg.alert('错误','保存失败!');
}
});
var json = Ext.JSON.decode(response.responseText); 此处是获得struts2action传来的数据
对json进行拆分处理便可获得所需要数据