Servlet 页面跳转 并弹出提示对话框
来源:互联网 发布:太乙神数排盘软件 编辑:程序博客网 时间:2024/04/26 22:00
<pre name="code" class="html">简单的登录验证模块点击登录进入相应的Servlet,Servlet调用bean验证用户名是否存在如果存在则登录成功,跳转如果不存在则弹出错误对话框,并回到登录页面开始用的下面两句话out.print("<script language='javascript'>alert('the name doesnot exit')</script>");response.sendRedirect("Login.jsp");但不会显示对话框,而是直接回到Login.jsp后来改用JOptionPane.showMessageDialog(null, "name doesnot exits");response.sendRedirect("Login.jsp");则可以实现。
@Overridepublic void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// TODO Auto-generated method stubrequest.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); String username=request.getParameter("username"); String password=request.getParameter("password"); String code=request.getParameter("code"); //状态码(0:默认值(用户未登入成功),1:用户登入成功,2:验证码通过) String message="0"; boolean target=false; if(username.equals("")){ username="0";} if(password.equals("")){ password="0"; } HttpSession sessions = request.getSession(); if(sessions.getAttribute("safecode")!=null ){ target=true; message="2"; } if(target){ String sql="select * from userinfo info where info.`username`='"+username.trim()+"' and info.`password`='"+password.trim()+"'"; try {ResultSet rusultset=DataBase.select(sql);while(rusultset.next()){message="1";HttpSession session = request.getSession();session.setAttribute("username",username);}DataBase.closeAll(rusultset);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();} } <span style="color:#ff0000;"> response.setContentType("text/;html"); PrintWriter out=response.getWriter(); //登入信息返回 if(message.equals("0")){//默认 JOptionPane.showMessageDialog(null, "用户名或密码不正确"); response.sendRedirect("./login.html"); }else if(message.equals("1")){//成功 response.sendRedirect("./message.html"); }else if(message.equals("2")){//用户名已经存在 JOptionPane.showMessageDialog(null, "注册码不正确"); response.sendRedirect("./login.html"); }else{//特殊情况 JOptionPane.showMessageDialog(null, "用户名或密码不正确"); response.sendRedirect("./login.html"); } out.flush(); out.close();</span> }@Overridepublic void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {// TODO Auto-generated method stubthis.doGet(request, response);}
0 0
- Servlet 页面跳转 并弹出提示对话框
- servlet跳转页面并弹出对话框
- servlet弹出提示框并跳转页面
- 弹出对话框并跳转页面
- MagicAjax 弹出对话框,并跳转页面
- ASP.NET弹出对话框并跳转页面
- 弹出对话框,页面跳转
- HTML页面弹出自定义对话框并跳转页…
- asp.net显示消息提示对话框,并进行页面跳转
- JS弹出框、对话框、提示框,JS关闭窗口、关闭页面和JS控制页面跳转
- 实现页面session验证,非法用户将弹出提示框并跳转页面
- Javascript弹出对话框并跳转方法
- 后台控制,前台弹出对话框,并跳转
- 先弹出对话框再跳转页面
- 弹出对话框,跳转到其它页面
- 先弹出对话框,然后跳转页面
- angularJS页面跳转后自动弹出对话框
- 在servlet中实现弹出提示框,点击确认后跳转其他页面
- unix - pipe
- HDU 1796 How many integers can you find 容斥(入门
- Android两种方式获取网络数据
- 基于C#的socket编程的TCP异步实现
- spring+struts整合
- Servlet 页面跳转 并弹出提示对话框
- unix-daemonize()
- Dimension作用?
- Intent和IntentFilter
- Quartz-Spring[一]之MethodInvokingJobDetailFactoryBean方法
- 四叉树空间索引原理及其实现
- 最大连续子序列
- 优先队列用法
- UVALive - 4108 SKYLINE 线段树(区间修改)