jsp页面无法验证帐号密码是否为空值,if(name!=null||name!="")这句话无效,请帮我分析下代码错误的原因
这是页面的完整代码<%@pagelanguage="java"import="java.sql.*"contentType="text/html;charset=GB23...
这是页面的完整代码
<%@ page language="java" import="java.sql.*" contentType="text/html;charset=GB2312"%>
<%
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e)
{out.println(e.getMessage());}
String name=(String)request.getParameter("s_name");
String password=(String)request.getParameter("s_pass");
String sname="",spassword="";
Connection conn=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
if(name!=null||name!="")
{
try
{
String strsql="select name,password from admin where name='"+name+"' and password='"+password+"'";
Statement st=conn.createStatement();
ResultSet rsLogin=st.executeQuery(strsql);
while(rsLogin.next())
{
sname=rsLogin.getString("name");
spassword=rsLogin.getString("password");
}
}
catch(Exception e)
{}
if(sname.equals(name)&&spassword.equals(password))
{
session.setAttribute("s_name",name);
%>
<jsp:forward page="6.jsp"/>
<%
}
else
{
out.println("<script>alert('用户名或者密码错误,请验证后再输入 ');window.history.go(-1);</script>");
}
}
conn.close();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'login.jsp' starting page</title>
</head>
<body>
</body></html>
这具页面输对帐号密码可以进入下一个页面,帐号密码为空也可以。帐号密码错误时弹出错误对话框,要怎么改才能让它在帐号密码为空值时也弹出错误对话框? 展开
<%@ page language="java" import="java.sql.*" contentType="text/html;charset=GB2312"%>
<%
try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");}
catch(ClassNotFoundException e)
{out.println(e.getMessage());}
String name=(String)request.getParameter("s_name");
String password=(String)request.getParameter("s_pass");
String sname="",spassword="";
Connection conn=DriverManager.getConnection("jdbc:odbc:ClassDB","sa","sa");
if(name!=null||name!="")
{
try
{
String strsql="select name,password from admin where name='"+name+"' and password='"+password+"'";
Statement st=conn.createStatement();
ResultSet rsLogin=st.executeQuery(strsql);
while(rsLogin.next())
{
sname=rsLogin.getString("name");
spassword=rsLogin.getString("password");
}
}
catch(Exception e)
{}
if(sname.equals(name)&&spassword.equals(password))
{
session.setAttribute("s_name",name);
%>
<jsp:forward page="6.jsp"/>
<%
}
else
{
out.println("<script>alert('用户名或者密码错误,请验证后再输入 ');window.history.go(-1);</script>");
}
}
conn.close();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'login.jsp' starting page</title>
</head>
<body>
</body></html>
这具页面输对帐号密码可以进入下一个页面,帐号密码为空也可以。帐号密码错误时弹出错误对话框,要怎么改才能让它在帐号密码为空值时也弹出错误对话框? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询