1 / 3

Página HTML

Código Javascript. 1. Pedido AJAX (JSON). Servlet. 3. Resposta AJAX (JSON). Página HTML. Classe do Modelo (Serviço). 4. jQuery (P.Ex.). 2. DTOs. Código Javascript $. ajax ( { type :'POST', url:'/ JSONeServicos / controller ', dataType :' json ', cache : false ,

louise
Télécharger la présentation

Página HTML

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Código Javascript 1. Pedido AJAX (JSON) Servlet 3. Resposta AJAX (JSON) Página HTML Classe do Modelo (Serviço) 4. jQuery (P.Ex.) 2. DTOs

  2. Código Javascript $.ajax( {type:'POST', url:'/JSONeServicos/controller', dataType:'json', cache:false, data:argumentos, // argumentos de ida... success: function(dadosDaResposta){ // Dados de retorno: dadosDaResposta // Função a ser chamada quando do retorno: callBack callBack(dadosDaResposta); }, error: function (xhr, ajaxOptions, thrownError){ // Fazer alguma coisa... } } )

  3. Servlet String nomeDaClasse = request.getParameter("nomeDaClasse"); String nomeDoMetodo = request.getParameter("nomeDoMetodo"); Class c = Class.forName(nomeDaClasse); Object obj = c.newInstance(); Method m = c.getMethod(nomeDoMetodo, HttpServletRequest.class, HttpServletResponse.class); responseDTO = (JsonDTO)m.invoke(obj,request,response); response.setContentType("application/json;charset=UTF-8"); Writer out = response.getWriter(); out.write(responseDTO.toString()); out.flush();

More Related