< % @ page import = "java.sql.DriverManager" % >
< % @ page import = "java.sql.Connection" % >
< % @ page import = "java.sql.Statement" % >
< % @ page import = "java.sql.ResultSet" % > < % --
Created by IntelliJ IDEA.
To change this template use File | Settings | File Templates.
-- % >
< % @ page contentType= "text/html;charset=UTF-8" language= "java" % >
< html>
< head>
< title> 主页< / title>
< / head>
< body>
< %
Class. forName ( "com.mysql.jdbc.Driver" ) ;
String url = "jdbc:mysql://localhost:3306/book" ;
Connection connection = DriverManager. getConnection ( url, "root" , "root" ) ;
Statement stmt = connection. createStatement ( ) ;
String sql = "select * from user where username = '" + request. getParameter ( "username" ) + "'" ;
ResultSet rs = stmt. executeQuery ( sql) ;
while ( rs. next ( ) ) {
out. print ( rs. getString ( "username" ) + "-" + rs. getString ( 3 ) + "<br>" ) ;
}
% >
< / body>
< / html>
< % --
Created by IntelliJ IDEA.
To change this template use File | Settings | File Templates.
-- % >
< % @ page contentType= "text/html;charset=UTF-8" language= "java" % >
< html>
< head>
< title> $Title$< / title>
< / head>
< body>
< form method= "post" action= "home.jsp" >
用户名: < input type= "text" name= "username" > < br>
密码: < input type= "text" name= "password" > < br>
< button type= "submit" > 注册< / button>
< / form>
< / body>
< / html>
< % @ page import = "java.sql.*" % > < % --
Created by IntelliJ IDEA.
To change this template use File | Settings | File Templates.
-- % >
< % @ page contentType= "text/html;charset=UTF-8" language= "java" % >
< html>
< head>
< title> 主页< / title>
< / head>
< body>
< %
Class. forName ( "com.mysql.jdbc.Driver" ) ;
String url = "jdbc:mysql://localhost:3306/book" ;
Connection connection = DriverManager. getConnection ( url, "root" , "root" ) ;
String sql = "select * from user where username = ? and password = ?" ;
PreparedStatement ps = connection. prepareStatement ( sql) ;
ps. setString ( 1 , request. getParameter ( "username" ) ) ;
ps. setString ( 2 , request. getParameter ( "password" ) ) ;
Statement stmt = connection. createStatement ( ) ;
ResultSet rs = ps. executeQuery ( ) ;
while ( rs. next ( ) ) {
out. print ( rs. getString ( "username" ) + "-" + rs. getString ( 3 ) + "<br>" ) ;
}
% >
< / body>
< / html>