删除成功或失败,在前台alert提示信息,并跳转页面
@RequestMapping("/delete.do")
public void deleteNews(String option, String id, HttpServletResponse response) {
response.setContentType("text/html;charset=utf-8");
String[] ids = null;
if (option.equals("deleteOnes")) {
ids = id.split("/");
}else {
ids = new String[] {id};
}
int row = ns.deleteNewsById(ids);
try {
PrintWriter writer = response.getWriter();
String msg = null;
if (row > 0) {
msg = "alert( '删除成功' );location.href='toIndex.do'";
}else {
msg = "alert('删除失败');history.go(-1)";
}
writer.print("<script type='text/javascript'>" + msg + "</script>");
writer.flush();
writer.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}