主题:为何不显示内容?
这段代码在输入错误的用户密码时什么都不显示,而不是返回到登陆页面
data为自定义的类,主要对数据库操作/
//jsp1.jsp
<%@ page contentType="text/html; charset=GBK" import="java.sql.*,mypro.*" %>
<html>
<head>
<script language="javascript" type="text/javascript" >
function f()
{
document.location="jsp2.jsp"
}
</script>
</head>
<body>
<%
data t=null;
ResultSet rs=null;
String str1=request.getParameter("n");
String str2=request.getParameter("ps");
boolean f=((str1==null)||(str2==null));
if(!f)
{
try
{t=new data();
str1=str1.trim();
str2=str2.trim();
String sql="select *from reg where username='"+str1+"'" +" and password='"+str2+"'";;
rs=t.getsql(sql);
rs.next();
out.print(rs.getString("username"));
out.print(rs.getString("password"));
Object o=(Object)rs;
if(o!=null)
{rs.close();
response.sendRedirect("jsp3.jsp");}
else
{rs.close();
out.println("<a href=‘jsp1.jsp’>用户名密码错误请先登陆</a>");}
}
catch(Exception e)
{}
}
else {%>
<form action="jsp1.jsp" name="mf" method="get">
用户名:
<input type="text" name="n" />
<br />
密码 :
<input type="password" name="ps" />
<input type="button" name="bt" value="注册" onclick="f()" />
<input type="submit" name="sb" value="登陆" />
<br />
</form>
<%} %>
</body>
</html>
data为自定义的类,主要对数据库操作/
//jsp1.jsp
<%@ page contentType="text/html; charset=GBK" import="java.sql.*,mypro.*" %>
<html>
<head>
<script language="javascript" type="text/javascript" >
function f()
{
document.location="jsp2.jsp"
}
</script>
</head>
<body>
<%
data t=null;
ResultSet rs=null;
String str1=request.getParameter("n");
String str2=request.getParameter("ps");
boolean f=((str1==null)||(str2==null));
if(!f)
{
try
{t=new data();
str1=str1.trim();
str2=str2.trim();
String sql="select *from reg where username='"+str1+"'" +" and password='"+str2+"'";;
rs=t.getsql(sql);
rs.next();
out.print(rs.getString("username"));
out.print(rs.getString("password"));
Object o=(Object)rs;
if(o!=null)
{rs.close();
response.sendRedirect("jsp3.jsp");}
else
{rs.close();
out.println("<a href=‘jsp1.jsp’>用户名密码错误请先登陆</a>");}
}
catch(Exception e)
{}
}
else {%>
<form action="jsp1.jsp" name="mf" method="get">
用户名:
<input type="text" name="n" />
<br />
密码 :
<input type="password" name="ps" />
<input type="button" name="bt" value="注册" onclick="f()" />
<input type="submit" name="sb" value="登陆" />
<br />
</form>
<%} %>
</body>
</html>