从Java Servlet显示SweetAlert

时间:2018-11-26 13:22:00

标签: javascript java jsp servlets sweetalert

我想将SweetAlert用于我的一个项目,但是当我从servlet中使用SweetAlert时,它是在打印行而不是Dialouge框

  

print.java //我的Servlet

public class print extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   String city = request.getParameter("cities");
        PrintWriter out = response.getWriter();
        out.println(city);

        out.println("<script src='https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/6.11.4/sweetalert2.all.js'></script>");
        out.println("<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>");
        out.println("<script src='https://unpkg.com/sweetalert/dist/sweetalert.min.js'></script");
        out.println("<script>");
        out.println("$(document).ready(function(){");
        out.println("swal('We Will Get Back To You Soon','Thank You','info');");
        out.println("});");
        out.println("</script>");
}

我以前在jsp页面上使用过Sweet Alert,即使我使用过这些servlet也是如此。但是突然之间,现在我遇到了这个。任何帮助将不胜感激

我得到的输出是,它只是打印上面的行

1 个答案:

答案 0 :(得分:0)

只需设置响应类型

  

response.setContentType(“ text / html”);

像魅力一样工作。