回 帖 发 新 帖 刷新版面

主题:一个很简单的问题求救用户登陆!!!!!!急急急!!

代码如下:
………………
<FORM name=form action=login.jsp method=post>
…………
login.jsp

<%@page contentType="text/html; charset=gb2312" language="java" %>
<%@ page    import="java.sql.*" %>
<%!
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
%>
<%
   String user=request.getParameter("username");
    String pwd=request.getParameter("password");
    user.trim();
    pwd.trim();
    boolean success=false;
    boolean valid=true;//判断用户是否重复登陆
String strSQL="select * from admin where username = '" + user+ "' and password = '" + pwd+ "'";

  try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");    //载入驱动程式类别
    Connection con = DriverManager.getConnection("jdbc:odbc:test3");    //建立资料库连线
    //建立Statement变量, 并设定记录指标类型为可前後移动
    Statement stmt = con.createStatement();
    ResultSet rs = stmt.executeQuery(strSQL);    //建立ResultSet(结果集)变量,并执行SQL语句
   }
    catch(Exception ex)
    {
        System.out.println(ex.toString());
    }
    
    if(rs.next())//判断用户输入的用户名和密码是不是admin和admin是就跳到upload.htm页面
     {     
         success=true;
         response.sendRedirect("http://www.163.com");
          
    }
    else
    {     success=false;
        response.sendRedirect("upload.htm");
        
    }

    
    rs.close(); //关闭ResultSet对象
    stmt.close(); //关闭Statement对象
    con.close();  //关闭Connection对象    
%>


运行是出现如下的错误:
HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:207)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:240)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:187)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:809)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:200)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:146)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:209)
    at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:596)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:433)
………………
        at java.lang.Thread.run(Thread.java:484)



--------------------------------------------------------------------------------

Apache Tomcat/4.1.31

回复列表 (共3个回复)

沙发

我的问题已经解决!谢谢!1

板凳

解决了就说出来嘛!!  自己解决了就不让别人知道错误在那里吗?

3 楼

这就是我修改后的代码:
<%@page contentType="text/html; charset=gb2312" language="java" %>
<%@ page import="java.sql.*" %>
<%
Connection con = null;
Statement stmt = null;
ResultSet rs = null;

    String user=request.getParameter("username");
    String pwd=request.getParameter("password");
    user.trim();
    pwd.trim();
    boolean success=false;
   
   
String strSQL="select id from admin where username = '" + user + "' and password = '" + pwd + "'";

  try
    {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");    //载入驱动程式类别
     con = DriverManager.getConnection("jdbc:odbc:test4");    //建立资料库连线
    //建立Statement变量, 并设定记录指标类型为可前後移动
    stmt = con.createStatement();
     rs = stmt.executeQuery(strSQL);    //建立ResultSet(结果集)变量,并执行SQL语句
   }
    catch(Exception ex)
    {
        System.out.println(ex.toString());
    }
    
    if(rs.next())//在admin表中寻找该用户
     {  
        
             success=true;
            response.sendRedirect("http://www.163.com");
     }     
    else
    {     success=false;
        response.sendRedirect("err.htm");
        
    }

    
    rs.close(); //关闭ResultSet对象
    stmt.close(); //关闭Statement对象
    con.close();  //关闭Connection对象    
%>


我来回复

您尚未登录,请登录后再回复。点此登录或注册