我的login.jsp的代码是这样的:
……(省略一点连接sql的语句)
if(rs.next())
{
Integer temp=new Integer(rs.getInt(1));
rs.close();
String customerid=temp.toString();
session.putValue("loginsign","OK");
session.putValue("cID","customerid");%>
<%response.sendRedirect("http://www.baidu.com");%>
<%
}
else
{
rs.close();
session.putValue("login_message","用户名错误或密码错误!");%>
<jsp:forward page="index.htm"/>
<%
}
%>
……(省略一些结尾的语句)
但是这样在index登陆时,不管是正确的输入还是错误的输入,他都只停留在login.jsp。为什么我的response.sendRedirect命令和jsp:forward page命令都没有起作用呢?
……(省略一点连接sql的语句)
if(rs.next())
{
Integer temp=new Integer(rs.getInt(1));
rs.close();
String customerid=temp.toString();
session.putValue("loginsign","OK");
session.putValue("cID","customerid");%>
<%response.sendRedirect("http://www.baidu.com");%>
<%
}
else
{
rs.close();
session.putValue("login_message","用户名错误或密码错误!");%>
<jsp:forward page="index.htm"/>
<%
}
%>
……(省略一些结尾的语句)
但是这样在index登陆时,不管是正确的输入还是错误的输入,他都只停留在login.jsp。为什么我的response.sendRedirect命令和jsp:forward page命令都没有起作用呢?
注意"<% %>"
String customerid=temp.toString();
session.putValue("loginsign","OK");
session.putValue("cID","customerid");%><%response.sendRedirect("http://www.baidu.com");%>
<%
<%@page contentType="text/html;charset=gb2312" %>
<%@page import="java.util.*"%>
<%@page import="java.net.URL"%>
<%@page import="java.sql.*"%>
<html>
<head>
<title>人员登陆</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<%!
String url;
String SQL;
%>
<%
String username=request.getParameter("username");
String password=request.getParameter("password");
url="jdbc:odbc:linglingzhongxuejijiandui";
SQL="select CustomerID from majorlogin where Username='"+username+"' and Password='"+password+"'";
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection(url,"sa","");
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("SQL");
if(rs.next())
{
Integer temp=new Integer(rs.getInt(1));
rs.close();
String customerid=temp.toString();
session.putValue("loginsign","OK");
session.putValue("cID","customerid");%><%response.sendRedirect
("http://www.baidu.com");%>
<%
}
else
{
rs.close();
session.putValue("login_message","用户名错误或密码错误!");%>
<jsp:forward page="index.htm"/>
<%
}
}catch (Exception e){
e.getMessage();
}
%>
</body>
</html>
可是现在不管在index的输入框中输入什么,页面也都只是到login.jsp为止了。不在跳转了。不管是百度的网页还是我自己的welcome.jsp页面都无法跳转过去。为什么呀?
如果你是怀疑><%response.sendRedirect
("http://www.baidu.com");%>
有问题, 你就写一个最简单的程序测试一下, 要学会调试....
如果不打印除了,说明转发语句根本没机会执行
这个错误什么意思啊?我用最简单的程序调试出来的信息~~~
所以没有警告出来。至于为什么不能连接数据源我至今未知……