后台像前台传出一个弹出框

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

PrintWriter out = null;
        try {
            out=response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
            out.print("error");
        }

···········
out.print("请重新输入!");
                return;

也可以有其他方式的操作,比如

PrintWriter out = null;
Gson gson = new Gson();
try {
     out = response.getWriter();
} catch (IOException e) {
     e.printStackTrace();
     out.print(gson.toJson("error"));
}
if (("").equals(haha) || null == haha){
      out.print(gson.toJson("不能为空!"));
      return;
}
String msg = "{\"flag\":\"success\"}";
                                

前台的解析

               $.ajax({
                    type:"POST",
                    url:"${requestContext.baseHref}xxx.html" + param,
                    dataType:"json",
                    success:function(msg){
                        if(msg!='error'){
                            if('success'==msg.flag){
                                
                            }else{
                                
                                alert(msg);
                            }
                        }else{
                            alert("请求出错");
                        }
                    },
                    error:function(msg){
                        alert("请求出错");
                    }
                });

 

转载于:https://my.oschina.net/sprouting/blog/806951

你可能感兴趣的:(后台像前台传出一个弹出框)