首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

如何样才能使err1异常提示和提交表单在一个页面显示

2012-02-03 
怎么样才能使err1错误提示和提交表单在一个页面显示下面的代码文件名称是adminlogin.asp!--#includefile

怎么样才能使err1错误提示和提交表单在一个页面显示
下面的代码文件名称是adminlogin.asp

<!--#include   file   =   '../includefile/include.asp '-->
<!--#include   file   =   '../includefile/judge.asp '-->
<%  
      dim   names
      dim   pass
      dim   err1
'if   Request.ServerVariables( "REQUEST_METHOD ")   =   "POST "   then  
      names   =   trim(Cstr(Request.Form( "username ")))
      pass   =   trim(Cstr(Request.Form( "password ")))
          if   names   =   Empty   or   pass   =   empty   then
                                err1   =   "错误:用户名和密码不能为空! "
                        response.write   err1
  end   if
          if   dx(names)   =   "true "   or   dx(pass)   =   "true "   then
              err1   =   "错误:用户名和密码只能在5-16个字符之间! "
                          response.write   err1
  end   if
          if   nochar(names)   =   "false "   or   nochar(pass)   =   "false "   then
              err1   =   "错误:用户名和密码只能在A-Z,a-z,0-9之间! "
                            response.write   err1
  end   if  
 
    if   len(err1)   =   0   then
  dim   sql1
Sql1   =   "SELECT   *   FROM   administrator   WHERE   username= ' "&names& " '   and   password= ' "&pass& " ' "
rs.open   sql1,con,1,1
  if   not   rs.eof   then
                Session( "username ")   =   names
        Session( "password ")   =   pass
                response.Redirect   "manage.asp "
rs.close()
set   rs   =   Nothing
con.close()
set   con   =   Nothing

response.Flush()
response.End()
else
response.write   " <font   color=red> <strong> 错误: </strong> </font> 用户名或密码错误! "
    response.end
end   if
end   if  
'end   if
%>  
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<title> 登录 </title>
<style>
<!--
.INPUT.buttonface{BACKGROUND:   #DDDDFF;   border:1   solid   #183ead;   COLOR:   #000000;   FONT-SIZE:   9pt;   FONT-STYLE:   normal;   FONT-VARIANT:   normal;   FONT-WEIGHT:   normal;   HEIGHT:   18px;   LINE-HEIGHT:   normal}
.snow1{   font-size:12px;   font-family: "宋体 ";   color:#000000}


.snow2{   font-size:24px;   font-family: "经典圆体简 ";   color:#ffffff}
-->
</style>
</head>
<body   background= "../image/userlogin/background.gif ">
<form   action= "adminlogin.asp "   method= "post "   name= "f1 ">
<table   align= "center "   cellspacing=0   border=0   cellpadding=2   width=350>
<tr   bgcolor= "#316AC5 ">
<td   align= "center "   colspan=2   height=35   class= "snow2 "> 管理员登录 </td>
</tr>
<tr   bgcolor= "silver ">
<td   align= "right "   height=40   class= "snow1 "   width=100   bgcolor= "#B5CBFF "> 管理员用户名: </td>
<td   align= "left "   bgcolor= "#ECF1FF "> <input   type= "text "   name= "username "   style= "width:120px; "> </td>
</tr>
<tr   bgcolor= "silver ">
<td   align= "right "   height=40   class= "snow1 "   bgcolor= "#B5CBFF "> 管理员密码: </td>
<td   align= "left "   bgcolor= "#ECF1FF "> <input   type= "password "   name= "password "   style= "width:120px; "> </td>
</tr>
<tr   bgcolor= "#316AC5 ">
<td   align= "center "   colspan=2   height=35>
<input   type= "submit "   value= "提交 "   class= "buttonface "> &nbsp;
<input   type= "reset "   name= "r1 "   value= "重置 "   class= "buttonface "> &nbsp;
</td>
</tr>
</table>
</form>
</body>
</html>


我把用户登陆表单   和   处理这个表单的程序放在了一起,我是想在本页面显示错误提示,但是一开始表单为空就提示错误,我怎么才能避免为空的错误?
请帮我改下,谢谢了

[解决办法]
加判断
if Session( "username ") = " "
登陆页面代码
elseif request( "username ")= " " ...
判断登陆和错误提示代码
else
主页面代码
end if



[解决办法]
写个js验证
function checkinfo(form){
if(form.username.value== ' '){
window.alert( '用户名不能为空 ');
form.username.focus();
return false;}
else if……
}
用onclick= "return checkinfo(this.value) "验证。这样不用刷新页面还能返回定位到出处的位置。
最好不要提交同一个页面处理。不方便修改管理。

热点排行