struts2 Action转换Map到JSON时报错,如何解决?
报错截图如下:
目前确认报错语句:
*JSONObject json = JSONObject.fromObject(map);
//map的类型声明:Map<String, Object> map = new HashMap<String, Object>();*
JSONaction类具体代码:
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("准备将map转换为json类型");
JSONObject json = JSONObject.fromObject(map);
result = json.toString();
}catch(Exception e) {
e.printStackTrace();
}
return "info";
}
}
浏览器客户端ajax由于action返回值失败也报错:
Failed to load resource: the server responded with a status of 500 ()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
异常贴全一点,NoClassDefFoundError 异常一般是少包或者包冲突。