
rs.open "select * from zhucebiao where username='"&username&"' and password='"&password&"'",cn,1,3
if rs.eof then
response.write "<script language=jscript>alert('对不起,您输入的用户名、密码或验证码有误,请重新输入,谢谢!')window.location.href='index.asp'</script>"
else
session("username")=rs("username") '就加在这里.
response.write "<script language=jscript>alert('登录成功!!')window.location.href='kehuliuyan.asp'</script>"
end if
end if
end if
%>
我觉得你那个alert登陆成功纯属多余.还有,你用的是脚本,如果对方关闭了浏览器脚本,那么你这个限制就多余了.意思就是,你这段代码基本算是废了.在服务器端验证的时候最好不要输出脚本.应该用response.redirect "kehuliuyan.asp"
我把你的代码改了,你看一下
<%set rs=server.createobject("adodb.recordset")
rs.open "select * from zhucebiao where username='"&username&"',cn,1,3
if rs.recordcount=0 then
response.write "<script language=jscript>alert(用户名错误!')window.location.href=='index.asp'</script>"
response.end
elseif rs("password")=password then
session("username")=rs("username")
response.redirct "kehuliuyan.asp"
elseif rs("password")<>password then
response.write "<script>alert('密码错误!')history.go(-1)</script>"
response.end
else
response.write"<script language=javascript>alert('输入有误,请检查后重新输入')history.go(-1)</script>"
response.end
end if
后面加上response.end 就算对方关闭了脚本也不会导致页面的继续执行.
这个是我把自己程序代码拿出来的,把变量改成了你的变量,如果再不行的话,那就可能是因为你的其它代码有误,还有,location.href后面应该是"=="而不是"="吧?
注意,在页面转换的时候,最好用response.redirct,因为它能够传递变量,而脚本不能,客户端脚本和服务器端一般除了表单提交是不能相互通信的,就是你<%url=kehuliuyan.asp%>不能用在location.href=='url'中.还有什么不懂的可以留言给我,看样子你也是刚学,验证代码写的太简陋了.
1:import 要放在<@ page标签内,必须在jsp开头。2:session,request,application,pagecontext这些是jsp的内置对象,在jsp页面内可以直接使用的,不需要配置,一次会话内所有的jsp或者servlet都可以调用setAttribute方法来设置session的属性,只能通过具体的页面调用来看了,这个谁也说不准是哪里set的
比如登录页面可以将用户名之类的统统set到session里,其他页面就可以直接get了
在jsp中使用js中的设置属性,进而获得session保存的属性值,实例如下:session设置:
session.setAttribute("username",username)
session.setAttribute("password",password)
session获取:
username=session.getAttribute("username")
password=session.getAttribute("password")
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)