如何将消息从servlet传递到引导模式

时间:2018-07-11 07:38:55

标签: java servlets bootstrap-modal

以下是servlet部分,在其中我得到了结果的价值。因此,我需要以模态展示此结果,在这种情况下,请提供帮助,因为我是新手。

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

        Services service = new Services();

        String dsid = request.getParameter("dsid");
        String name = request.getParameter("name");
        String superadmin = request.getParameter("gridRadios");
        Boolean admin = null;
        if (superadmin.equalsIgnoreCase("Yes")) {
            admin = true;
        } else {
            admin = false;
        }
        String region = request.getParameter("region");

        String result = service.addAssociate(dsid, name, admin, region);

        // System.out.println("Result: " + result);
        response.getWriter().write(result);



    //I need to show value of 'result' in bootstrap modal


    }

}

这是我想展示结果价值的模态:

<div class="modal fade" id="success_msg" role="dialog" tabindex="-1">
<div class="success">
  <div class="modal-dialog-success">
    <div class="col-xs-12 pade_none">
      <button type="button" class="close" onClick="closeConfirm();" data-dismiss="modal">&times;</button>
      <div class="col-xs-12 pade_none">
           <p>Message to be shown over here</p>
      </div>
      <div class="col-xs-12 pad_none">
      </div>
    </div>
  </div>
</div>
</div>

1 个答案:

答案 0 :(得分:1)

代替response.getWriter().write(result) 您需要将请求转发到目标页面。

RequestDispatcher dispatcher= request.getRequestDispatcher("/target.jsp");
request.setAttribute("result",result);

dispatcher.forward(request,response);

位于target.jsp

<!--omit bootstrap boilerplate-->
<!--use jstl-->
<c:out value="${requestScope.result}"></c:out>

<%
String result = (String)request.getAttribute("result");
%>


<!--omit bootstrap boilerplate-->
<%=result%>