簡體   English   中英

如何從JSP頁面獲得登錄名? 如何更正我的jsp代碼。

[英]How can I get a Login from JSP page? How can I correct my jsp code.?

我在這里錯了我該如何糾正

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

我唯一錯的是這是jsp中的登錄頁面。我唯一錯的是這是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:              `

您有語法錯誤。 嘗試使用以下語法。

<% 
 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);
     }
   %>

您忘了關門了。 您可以使用}進行嘗試,但沒有一個用於關閉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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM