为什么if里面的句子判断不出啊
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ page import="java.sql.*"%>
<script language="javascript">
function on_submit(){
if(form1.username.value=="")
{
alert("用户名不能为空,请输入用户名");
form1.username.focus();
return false;
}
if(form1.userpassword.value=="")
{
alert("密码不能为空,请输入密码");
form1.username.focus();
return false;
}
}
</script>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<table align="center">
<form name="form1" method="post" action="" onsubmit="return on_submit()">
<tr align="center">
<td>
请输入用户名:<input type="text" name="username" size="20">
</td>
</tr>
<tr align="center">
<td>
请输入密码: <input type="password" name="userpassword" size="20">
</td>
</tr>
<tr align="center">
<td>
<input type="submit" name="B1" value="提交">
<input type="reset" name="B2" value="全部重写">
</td>
</tr>
</form>
</table>
<%
if(request.getParameter("username")!=null){
Connection con;
Statement sql;
ResultSet rs;
String a=request.getParameter("username");
String a1;
try{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
}
catch(ClassNotFoundException e){
out.print("类找不到");
}
try{
con=DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=checkdb","sa","");
sql=con.createStatement();
rs=sql.executeQuery("SELECT * FROM login");
while(rs.next()){
a1=rs.getString("username");
out.print(a1);
}
}
catch(SQLException el){
out.print(el.toString());
}
if(a.equals("a1")){
out.print("成功");
}
}
%>
</body>
</html>
主要是不明白为什么if(a.equals("a1")){
out.print("成功");
}
里面的out.print("成功");执行不到啊?我事先已经在数据库里设定username为admin,if里的条件应该为真才对,可是为什么不能执行里面的语句啊?是不是从数据库里返回的字符串加了空格所以不相等啊?如果是那该怎么判断相等啊?