Screenshot of error message is as follows:
current confirmation error statement:
*JSONObject json = JSONObject.fromObject(map);
//map:Map<String, Object> map = new HashMap<String, Object>();*
JSONaction class specific code:
package com.yzpc.action;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import net.sf.json.JSONObject;
import org.apache.struts2.interceptor.ServletRequestAware;
import com.opensymphony.xwork2.ActionSupport;
import com.yzpc.biz.StuBiz;
import com.yzpc.bean.Stu;
public class JsonAction extends ActionSupport implements ServletRequestAware{
private HttpServletRequest request;
private String result;
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
public String infoAjax() {
StuBiz stuBiz = new StuBiz();
Stu stu = new Stu();
try {
String id = request.getParameter("stu_id");
System.out.println(id);
Map<String, Object> map = new HashMap<String, Object>();
stu = stuBiz.getStuById(id);
String stu_id = stu.getStu_id();
String stu_name = stu.getStu_name();
int age = stu.getAge();
String sex = stu.getSex();
String specialty = stu.getSpecialty();
String email = stu.getEmail();
String telephone = stu.getTelphone();
map.put("stu_id", stu_id );
map.put("stu_name", stu_name);
map.put("age", age);
map.put("sex", sex);
map.put("telephone", telephone);
map.put("email", email);
map.put("specialty", specialty);
System.out.println("mapjson");
JSONObject json = JSONObject.fromObject(map);
result = json.toString();
}catch(Exception e) {
e.printStackTrace();
}
return "info";
}
}
browser client ajax also reported an error due to failure of action return value:
Failed to load resource: the server responded with a status of 500 ()