需求:
Controller层直接alert
实现:
protected String alert(HttpServletResponse response, String msg, String url) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "text/html;charset=UTF-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.print("<script>alert('" + msg + "');window.location.href='"
+ url + "';</script>");
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(out);
}
return "common/suc";
}
protected void alertAndclose(HttpServletResponse response, String msg) {
response.setCharacterEncoding("UTF-8");
response.setHeader("Content-type", "text/html;charset=UTF-8");
PrintWriter out = null;
try {
out = response.getWriter();
out.print("<script>alert('" + msg + "');window.close();</script>");
out.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(out);
}
}