在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/Java  HTML/ struts2 Action轉(zhuǎn)換Map到JSON時(shí)報(bào)錯(cuò),如何解決?

struts2 Action轉(zhuǎn)換Map到JSON時(shí)報(bào)錯(cuò),如何解決?

報(bào)錯(cuò)截圖如下:
clipboard.png

目前確認(rèn)報(bào)錯(cuò)語(yǔ)句:

*JSONObject json = JSONObject.fromObject(map);
//map的類(lèi)型聲明:Map<String, Object> map = new HashMap<String, Object>();*
       
       

JSONaction類(lèi)具體代碼:

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("準(zhǔn)備將map轉(zhuǎn)換為json類(lèi)型");
            JSONObject json = JSONObject.fromObject(map);
            result = json.toString();
            
        }catch(Exception e) {
            e.printStackTrace();
        }
        return "info";
    }
    
}

瀏覽器客戶端ajax由于action返回值失敗也報(bào)錯(cuò):
Failed to load resource: the server responded with a status of 500 ()

回答
編輯回答
護(hù)她命

異常貼全一點(diǎn),NoClassDefFoundError 異常一般是少包或者包沖突。

2017年10月24日 23:00