weixin_33725270 2019-04-21 16:42 采纳率: 0%
浏览 64

使用AJAX请求分派器

I'm sending a POST form using AJAX, and i'm trying to send back this value to my JSP, but I do not know exactly how to do it .

This is my AJAX.

 function ajax() {

    var e = document.getElementById("combo2");
    var e2 = e.options[e.selectedIndex].value;


    $.post( "MiddleContentApi", { cidades: e2})
        .done(function( data ) {
            alert( "Data Loaded: " + data );
        });
}

document.getElementById("okCity").addEventListener("click",ajax);

My Servlet :

   public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

    Integer cidadeId = Integer.parseInt(request.getParameter("cidades"));
      System.out.print(cidadeId);
    response.setContentType("text/html;charset=UTF-8");
    response.getWriter().write(String.valueOf(cidadeId));
}

Ajax is working totally ok, the value is returning to my "data" and the alert(data) is working either, but what I really need is to access this value returned using scriptles <% %> in jsp, but if I try to do something like :

      public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

      Integer cidadeId = Integer.parseInt(request.getParameter("cidades"));
          request.setAttribute("numero",cidadeId);
          RequestDispatcher rd = request.getRequestDispatcher("estados.jsp");
          rd.forward(request,response);

            }

This's just not working, and I can't acess the data in jsp by using :

   Object jbo = request.getAttribute("numero");

Does someone now how can I do this?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料