struts2弹出信息提示
在struts2 action中弹出Js脚本提示信息
public class StudentAction extends ActionSupport { public String addStudent(){ HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=UTF-8"); response.setCharacterEncoding("UTF-8");//防止弹出的信息出现乱码 PrintWriter out = null;try {out = response.getWriter();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} studentDAO=new StudentDAO(); flag=studentDAO.addStudent(stu); if(flag){ out.print("<script>alert('添加成功!')</script>"); out.print("<script>window.location.href='stuaction.action'</script>"); out.flush(); out.close(); return null; }else{ return "error"; } }}