Home > Back-end >  The JSP login to connect to the database login no matter right or wrong, only enter a page
The JSP login to connect to the database login no matter right or wrong, only enter a page

Time:09-27

Connected to the database code:
& lt; % @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;
& lt; % @ page import="Java. SQL. *" % & gt;
& lt; ! PUBLIC DOCTYPE HTML "-////W3C DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" & gt;
& lt; html>
& lt; head>
& lt; Meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "& gt;
& lt; title> Insert the title here
& lt;/head>
& lt; body>

& lt; %
String name1=request. The getParameter (" name ");
String password1=request. The getParameter (" password ");

//registered JDBC
Class.forName("com.mysql.jdbc.Driver");
//open the link
The Connection conn=(Connection) DriverManager. GetConnection (" JDBC: mysql://localhost: 3306/mysqljdbc ", "root", "root");
The Statement STMT=(Statement) conn. CreateStatement ();
String SQL=(" select * from t_test ");
The ResultSet rs=STMT. ExecuteQuery (SQL);
If (rs. Next ())
{
Int id=rs. Get int (" id ");
String usname=rs. Get String (" name ");
String uspassword=rs. Get String (" password ");
If (name1. Equals (usname) & amp; & Password1. Equals (uspassword))
{
Response. SendRedirect (" denglu. JSP ");
}

The else {
Response. SendRedirect (" dlsuccess. JSP ");
}

}
rs.close();
conn.close();


%>
& lt;/body>
& lt;/html>

Login interface:

& lt; % @ page language="Java" contentType="text/HTML. Charset=utf-8 "
PageEncoding="utf-8" % & gt;

& lt; ! PUBLIC DOCTYPE HTML "-////W3C DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd" & gt;
& lt; html>
& lt; head>
& lt; Meta HTTP - equiv="content-type" Content="text/HTML. Charset=utf-8 "& gt;
& lt; title> The login page & lt;/title>


& lt;/head>
& lt; body>





& lt; The form method="post" action="shujuku. JSP & gt;"

User name: & lt; Input type="text" name="name" & gt; & lt; br>
Password: & lt; Input the name="password" type="password" & gt; & lt; br>
& lt; Input type="submit" value="https://bbs.csdn.net/topics/" & gt;

& lt; Input type="reset" value="https://bbs.csdn.net/topics/reset & gt;" & lt; br>

& lt;/form>

& lt;/body>
& lt;/html>

Can be registered with the database, is landing has a problem, to login dlsuccess. JSP.

CodePudding user response:

Please everyone a great god, save the children
  • Related