controller分支实现前台显示弹框同时转发
controller分支实现前台显示弹框,前台不需要进行什么操作, 前台请求后台的分支即可。
controller层(标红的地方是(alert('账号或密码错误!请重新输入!!!!') window.location.href='/index.jsp'):弹出一个弹框,然后跳转一个页面,如果你只想弹个弹框可以把跳转的页面去掉。):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | @RequestMapping ( "/isLogin" ) public Object isLogin(HttpServletRequest request, String uname, String upwd, HttpServletResponse response) throws IOException { Userinfo userinfo= new Userinfo(); userinfo.setUname(uname); userinfo.setUpwd(upwd); Userinfo login = service.login(userinfo); response.setContentType( "text/html;charset=utf-8" ); PrintWriter out=response.getWriter(); if (login!= null ){ System.out.println( "0" ); return "/index.jsp" ; } else { //out.print("<script language=\"javascript\">alert('登录失败!');</script>"); out.print( "<script language=\"javascript\">alert('账号或密码错误!请重新输入!!!!');window.location.href='/index.jsp'</script>" ); System.out.println( "1" ); return out; } } |
页面:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <%@ page language= "java" contentType= "text/html; utf-8" isELIgnored= "false" pageEncoding= "utf-8" %> <html> <title>我是登录</title> <body> <h2>Hello World!</h2> <form action= "/isLogin" method= "post" > 用户:<input type= "text" name= "uname" ><br> 密码:<input type= "text" name= "upwd" ><br><br> <input type= "submit" value= "确定登录" > <button><a href= "uen.jsp" >点击注册</a></button> </form> </body> </html> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】凌霞软件回馈社区,携手博客园推出1Panel与Halo联合会员
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· MySQL下200GB大表备份,利用传输表空间解决停服发版表备份问题
· 记一次 .NET某固高运动卡测试 卡慢分析
· 微服务架构学习与思考:微服务拆分的原则
· 记一次 .NET某云HIS系统 CPU爆高分析
· 如果单表数据量大,只能考虑分库分表吗?
· 7 个最近很火的开源项目「GitHub 热点速览」
· DeepSeekV3:写代码很强了
· MySQL下200GB大表备份,利用传输表空间解决停服发版表备份问题
· Visual Studio 2022 v17.13新版发布:强化稳定性和安全,助力 .NET 开发提
· AI浏览器自动化实战