2016-07-28 8 views
1

私はこれがjsp.Iにログインページでのみここで間違っていますどのように私はこの[JSPからログイン]ページを取得するにはどうすればよいですか?私のJSPコードを修正するには?

String Sql="select * from login where username='"+name+"' AND password='"+abc+"'"; 
c1.st.executeQuery(Sql); 
{ 
    out.println("aa"); 
} 
catch(SQLException ex) 
{ 

を修正することができ、ここで間違っているが、これは、JSPでのログインページで、ここだけ間違っています。

デシベルのconn.jsp

<%@page import="com.mysql.jdbc.Connection"%> 
<%@page import="com.mysql.jdbc.Statement"%> 
<%@page import="java.sql.ResultSet"%> 
<%@page import="java.sql.DriverManager"%> 
<%@page contentType="text/html" pageEncoding="UTF-8"%> 
<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title>JSP Page</title> 
</head> 
<body> 
    <h1>Hello World!</h1> 

    <%@ page import ="java.sql.*" %> 
    <% 
    Connection c1 = null; 
    Statement st = null; 
    ResultSet rs = null; 

    try { 
    Class.forName("com.mysql.jdbc.Driver"); 
    c1 = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/teacher","root", "abcde"); 
     } 
    catch (Exception cnfe) { 
    System.out.println("Couldn't find the driver!"); 
    System.out.println("Couldn't connect: print out a stack trace and exit."); 
    System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected."); 
     } 
    try { 
    st = (Statement) c1.createStatement(); 
    System.out.println("Statement Created Successfully"); 
    } catch (SQLException se) { 
    System.out.println("We got an exception while creating a statement:" + "that probably means we're no longer connected."); 
    se.printStackTrace(); 
    } 
    if (c1 != null) { 
    System. out.println("Hooray! We connected to the database!"); 
    } else { 
    System.out.println("We should never get here."); 
    } 
    %> 

    <% 
    try{ 
     String name=request.getParameter("username"); 
     String abc=request.getParameter("password"); 

     String Sql="select * from login where username='"+name+"' AND password='"+abc+"'"; 

     c1.st.executeQuery(Sql); 
     { out.println("aa"); 
     } 
     catch(SQLException ex) 
     { 
     out.println(ex); 
     }} 
     %> 

エラー:

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: Unable to compile class for JSP: 
     An error occurred at line: 60 in the jsp file: /db conn.jsp  
     c1.st cannot be resolved or is not a field 
     57:    
     58: String Sql="select * from login where username='"+name+"' AND password='"+abc+"'"; 
     59:         
     60: c1.st.executeQuery(Sql); 
     61: { 
     62: out.println("aa"); 
     An error occurred at line: 63 in the jsp file: /db conn.jsp 
     Syntax error, insert "}" to complete Block 
     60: c1.st.executeQuery(Sql); 
     61: { 
     62: out.println("aa"); 
     63: } 
     64:    
     65: catch(SQLException ex) 
     66:    ` 

答えて

1

あなたは構文エラーがあります。次の構文を使用してみてください。

<% 
try{ 
    String name=request.getParameter("username"); 
    String abc=request.getParameter("password"); 

    String Sql="select * from login where username='"+name+"' AND password='"+abc+"'"; 

    c1.st.executeQuery(Sql); 
     out.println("aa"); 
    } 
    catch(SQLException ex) 
    { 
    out.println(ex); 
    } 
    %> 
+1

あなたは 'デシベルconn.jsp'の私のコードを修正しようとしないのはなぜ –

1

ブロックを閉じるのを忘れました。あなたは試してみるために1 }を持ってではなく、1 out.printlnを(「AA」)を閉じる:

try{ 
    String name=request.getParameter("username"); 
    String abc=request.getParameter("password"); 

    String Sql="select * from login where username='"+name+"' AND password='"+abc+"'"; 

    c1.st.executeQuery(Sql); 
    { out.println("aa"); **}** -> you forgot this bracket 
    } 
    cat 
+0

なぜ 'db conn.jsp'のコードを修正しようとしないのですか –

+0

私はしました。エラーはconn.jspにあり、そこに別の}を入れる必要があります。 –

関連する問題