Spring MVC alert prompt in the original page

 A wording:

    @RequestMapping("/testAlert") 
    public ModelAndView pay(HttpServletResponse response) throws IOException{
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.print("<script type='text/javascript'>alert('成功!');</script>");  
        ModelAndView mv=new ModelAndView();
        mv.setViewName("index");
        return mv;
    }        

Writing two (forward while the pop-up dialog box):

@RequestMapping(value="/user/index",method=RequestMethod.POST)
public String checkLogin(@RequestParam("userName") String userName,
                         @RequestParam("password") String password,
                         HttpServletResponse response) throws IOException{
    //根据用户名userName和密码password查看是否是非法用户,此处代码略
    response.setContentType("text/html;charset=gb2312");
    PrintWriter out = response.getWriter();
    if(非法用户){
        out.print("<script language=\"javascript\">alert('登录失败!');window.location.href='/你的工程名/login'</script>");    
            //弹窗提示并跳转到其他页面
        return "/login";
    }
    return "/user/index"; 
 }
 

Written three:

@RequestMapping("/testAlert.do")
	public void deleteNews(HttpServletResponse response) {
		response.setContentType("text/html;charset=utf-8");
                PrintWriter writer = response.getWriter();
		msg = "alert('删除失败');history.go(-1)";    //回到上一个页面
		writer.print("<script type='text/javascript'>" + msg + "</script>");
		writer.flush();
		writer.close();
        catch (IOException e1) {
		e1.printStackTrace();
		}
	}

 

Published 35 original articles · won praise 2 · Views 1375

Guess you like

Origin blog.csdn.net/weixin_41001497/article/details/104029103