`
姜中秋
  • 浏览: 86153 次
  • 性别: Icon_minigender_1
社区版块
存档分类
最新评论

Extjs 与 struts2 结合

阅读更多
实际应用
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进行拆分处理便可获得所需要数据
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics