0
這是我的servlet:json數組有對象「esquina」。埃斯基納有兩個屬性,雙重coordX雙coordY我怎麼能從json數據從java servlet到jquery
package servlets;
@WebServlet("/Mapa")
public class ServletMapa extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ServletMapa() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Sistema instanciaSys = Sistema.darInstancia();
instanciaSys.inicializarSistema(6);
Esquina[] esquinas = instanciaSys.getEsquinas();
JSONArray json =new JSONArray();
JSONObject jO = null;
for (Esquina esquina : esquinas) {
jO = new JSONObject(esquina);
json.put(jO);
System.out.println(json);
}
request.setAttribute("esquinas", esquinas);
request.setAttribute("json", json);
request.getRequestDispatcher("/gui/Mapa.jsp").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
我需要從jsonArray獲取數據到jQuery的,我試過的getJSON()函數,但沒有工作。
here's代碼
function cargarMarcadores() {
var x=$("#iniSistema");
x.click(function(){
$.getJSON('localhost:8080/Carpuleame/Mapa',function(data){
alert("data");
});
});
}
有antoher辦法做到這一點?
謝謝,我需要這些coordenates來放置一個標記(谷歌地圖api)。 –
很酷。如果我解決了您的問題,請考慮接受答案。 – bcholmes