我用struts1.x+jquery+ajax+json 做一个异步提交,我知道用$.ajax()提交,但是我有两个问题,第一,我传入的地方是dispatchAction,url是 *****.do?flag=query,但是我不知道怎么接收这个传过来的对象,我用String str =request.getParameter("arrData")返回的Str是个null,第二,因为这个分派action固定了返回类型,所以我也不知道怎么返回将处理后转变的json传出来了!急求!求大神解答!!!
------解决方案--------------------
$.ajax({
url:ctx+"/formulaAction.do",
type:"post",
dataType:"json",
data:{
method:"getParaList",
strategyId:id,
strategyName:name
},
------解决方案--------------------
public void getParaList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
FormulaActionForm formulaForm=(FormulaActionForm) form;
int strategyId=formulaForm.getStrategyId();
String strategyName=formulaForm.getStrategyName();
HttpSession session = request.getSession(true);
String username = (String) session.getAttribute("username");
String password = (String) session.getAttribute("password");
FormulaBean fb=new FormulaBean();
List<StrategyObjectParam> fpList=fb.getParaList(username, password, strategyId, strategyName);
formulaForm.setFpList(fpList);
JSONArray jsonArray=new JSONArray();
for(int i=0;i<fpList.size();i++){
JSONObject json=new JSONObject();
FormulaParam fp=fpList.get(i).getTemplate();
json.put("strategyId", fp.getStrategyId());
json.put("strategyName", fp.getStrategyName());
json.put("name", fp.getName());
json.put("minVal", fp.getMinVal());
json.put("maxVal", fp.getMaxVal());
json.put("defaultVal", fp.getDefaultVal());
json.put("desc", fp.getDesc().toStringUtf8());
json.put("stepVal", fp.getStepVal());
jsonArray.add(json);
}
try {
this.outputJson(response, jsonArray);
} catch (Exception e) {
e.printStackTrace();
}
}
public void outputJson(HttpServletResponse response, JSONArray json)
throws Exception {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println(json);
out.flush();
}