我的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命令都没有起作用呢?

解决方案 »

  1.   

    不能有空格.
    注意"<% %>"
               String customerid=temp.toString();
               session.putValue("loginsign","OK");
               session.putValue("cID","customerid");%><%response.sendRedirect("http://www.baidu.com");%>
    <%
      

  2.   

    可能语句在到达response.sendRedirect之前就已经抛异常了
      

  3.   

    我login.jsp的完全代码是这样的:
    <%@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页面都无法跳转过去。为什么呀?
      

  4.   

    NI 你先确定你的程序进入了if语句...
    如果你是怀疑><%response.sendRedirect
    ("http://www.baidu.com");%>
    有问题, 你就写一个最简单的程序测试一下,  要学会调试....
      

  5.   

    在<%response.sendRedirect("http://www.baidu.com");%>前面加一个System.out.print("ddddddd")
    如果不打印除了,说明转发语句根本没机会执行
      

  6.   

    IM002 [Microsoft][ODBC 驱动程序管理器] 未发现数据源名称并且未指定默认驱动程序 0 
    这个错误什么意思啊?我用最简单的程序调试出来的信息~~~
      

  7.   

    控制面板里面的设置?都设置好了。用JAVA可以连接显示的。但是用jsp就出现这个问题了。
      

  8.   

    Integer temp=new Integer(rs.getInt(1));为啥要这么写呢
      

  9.   

    控制面板里面的设置是正确的呀。因为用JAVA小程序是可以连接到数据库的。但是用jsp就显示数据源有问题。
      

  10.   

    ResultSet rs=stmt.executeQuery("SQL");你怎么把SQL给引起来了 这样RS是NULL,你下面的RS。CLOSE()就出错了  不过不知道为什么不提示!
      

  11.   

    我SQL这个字符串变量前面已经赋值了呀
    所以没有警告出来。至于为什么不能连接数据源我至今未知……