JSP内置对象之--response登录验证
来源:互联网 发布:游戏宣传片制作软件 编辑:程序博客网 时间:2024/06/07 13:21
验证操作顺序:
提交
取
判断(空空判断-->匹配 -->成功--> 跳转[])
<%@ page contentType = "text/html" pageEncoding= "GBK"%><html><head>登陆验证</head><body><form action = "login.jsp" method = "post">用户名:<input type ="text" name = "uname"><br>密 码:<input type = "password" name = "upassword"><br><input type = "submit" value ="提交"><input type = "reset" value ="重置"></form><%String name = request.getParameter("uname");String password = request.getParameter("upassword");if ("zhangze".equals(name) && "lhj".equals(password)){response.setHeader("refresh", "3; URL = welcome.jsp");session.setAttribute("userid",name);%><h3>登录成功,三秒后跳转到欢迎页!</h3><h3>如果浏览器无法跳转,请点击<a href="welcom.jsp"></a>这里</h3><%}else {%><h3>错误的用户名或密码</h3><%}%></body></html>打开页面未填写就出错原因:未加表单内容空空判断。
提交到自己本页:
<%@ page contentType = "text/html" pageEncoding= "GBK"%><html><head>登陆验证</head><body><form action = "login.jsp" method = "post">用户名:<input type ="text" name = "uname"><br>密 码:<input type = "password" name = "upassword"><br><input type = "submit" value ="提交"><input type = "reset" value ="重置"></form><%String name = request.getParameter("uname");String password = request.getParameter("upassword");if (!(name==null || "".equals(name) || password==null || "".equals(password))){if ("zhangze".equals(name) && "lhj".equals(password)){response.setHeader("refresh", "3; URL = welcome.jsp");session.setAttribute("userid",name);%><h3>登录成功,三秒后跳转到欢迎页!</h3><h3>如果浏览器无法跳转,请点击<a href="welcom.jsp"></a>这里</h3><%}else {%><h3>错误的用户名或密码</h3><%}}%></body></html>
加上空空判断后的登录首页效果:
welcome.jsp
<%@ page contentType ="text/html" pageEncoding ="GBK"%><html><head><title>欢迎页!</title></head><body><%if(session.getAttribute("userid")!=null){%><h3>欢迎<%=session.getAttribute("userid")%>登录本欢迎页,<a href="logout.jsp">注销</a></h3><%}else {%><h3>请进行系统的的<a href="login.jsp">登录</a></h3><%}%></body></html>
登录成功后的 欢迎页:
logout.jsp
<%@ page contentType ="text/html" pageEncoding ="GBK"%><html><head><title>注销页</title></head><body><%response.setHeader("refresh", "3; URL = welcome.jsp");session.invalidate();%><h3>您已经退出本系统,两秒后回到系统首页</h3><h3>如果没有跳转,请点击<a href="login.jsp"></a>这里</h3></body></html>
- JSP内置对象之--response登录验证
- JSP内置对象之response
- JSP内置对象之response对象
- JSP内置对象之response对象
- JSP内置对象之response对象
- jsp内置对象之response对象
- JSP内置对象之request和response
- JSP内置对象之------response、session、application
- JSP内置对象之out request response
- JSP内置对象----response
- JSP内置对象----response
- JSP内置对象---response
- JSP内置对象response
- JSP内置对象---response
- JSP 内置对象Response
- jsp内置对象response
- JSP内置对象response
- JSP内置对象详解2 之 response内置对象
- [bfs] poj 1753 Flip Game# bfs + 位存储
- 计算机网络层(3)--------《计算机网络-自顶向下方法》
- ACM水题-数据选取(AC解题报告)
- jndi详解
- Android面试之---谈谈你对Android NDK的理解
- JSP内置对象之--response登录验证
- Android 下载安装APK
- mfc绘图 结构与函数大全
- 返回局部对象的引用和返回局部对象的指针
- Spring Security学习笔记
- Android面试之----谈谈你对Java中Native关键字的认识!
- 初识Socket之构造接受包的简易程序(C语言实习)
- 查看SAP HANA DB 和SAP HANA studio的版本
- 通过json自定义extjs 消息框