0
我是新手。我使用httpservlet響應從struts動作發送數據。我應該怎麼做才能在javascript中檢索這個值來將這些值設置爲html元素。如何通過解析json數據來檢索從javascript中的struts動作發送的值
使用Struts動作和httpservlet對象寫入響應。
Gson gson = new Gson(); //using gson-2.3.1.jar
//log.debug("Printing values ... ");
//log.debug(gson.toJson(languagesResponse.getLanguages()));
response.setContentType("application/json");
// Get the printwriter object from response to write the required json object to the output stream
PrintWriter out = response.getWriter();
// Assuming your json object is **jsonObject**, perform the following, it will return your json object
out.print(gson.toJson(languagesResponse.getLanguages()));
out.flush();
讓JSON返回值:
[{ 「stringCode」: 「默認」, 「numberCode」:0, 「__ hashCodeCalc」:假},{ 「stringCode」: 「EN_US」 ,「numberCode」:1,「__ hashCodeCalc」:false}]
我想爲javascript elemtent獲取此值。
我知道它的客戶端代碼來處理,但我不知道我應該怎麼在客戶端獲得響應數據.. – k00989 2014-12-19 06:47:13
你有沒有檢查我提供的鏈接?那些應該有相當廣泛的材料來處理你所問的所有問題。 – 2014-12-19 06:48:22