In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces JSP dynamic how to achieve web web page login and registration functions, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Preface
The relevant contents are as follows:
Database installation
JSP web pages connect to the database
JSP page for registration and login
Database
Installation tutorial
Software installation
(visual database interface software installation) you are welcome to take it
Link extraction code: qwer
JSP web page connection database configuration mysql file
First, copy the mysql-connector-java-5.0.8-bin.jar to the apache-tomcat-10.0.12-windows-x64\ apache-tomcat-10.0.12\ lib file directory
Create a jsp file, connect to the database, and read the data displayed in the jsp Insert title here page
The connection is successful, and the page is displayed as follows
Registration and login JSP page New login.jsp file LOGIN login account password login new check.jsp Insert title here create register.jsp file registration interface Register Click to register new Cregister.jsp file Insert title here--% > create DBBean.java file package MySql Import java.sql.* Public class DBUtil {/ * 1, * mysql5 and previous versions use the old driver "com.mysql.jdbc.Driver" * mysql6, and later versions need to be updated to the new version of the driver. The corresponding Driver is "com.mysql.cj.jdbc.Driver" * 2, * com.mysql.cj.jdbc.Driver *, which is a class in a set of JDBC interfaces implemented by database vendors. It is called "driver class", and its inheritance tree is as follows: *-com.mysql.jdbc.Driver extends com.mysql.cj.jdbc.Driver *-com.mysql.cj.jdbc.Driver extends NonRegisteringDriver *-public class NonRegisteringDriver implements java.sql.Driver * 3. * java.sql is the official package provided by sun. Java.sql.Driver is one of a group of interfaces provided by sun to connect to the database, which is implemented by the database vendor * it can be seen from the above that the driver class com.mysql.cj.jdbc.Driver is the implementation of the java.sql.Driver interface * / private String driverStr = "com.mysql.cj.jdbc.Driver" / / the first point above explains why you need to add cj private String connStr = "jdbc:mysql://localhost:3306/ user table"; / / this is equivalent to the url (address) private String dbusername of the local database = "root"; / / the account number of the database private String dbpassword = "123456"; / / the password of the database needs to be modified by everyone, which can be modified by using SQL statement on the console. / *-Statement: created by createStatement and used to send simple SQL statements (without parameters) Statement createStatement () throws SQLException * / private Statement stmt = null; public DBUtil () {try {/ * after loading this class com.mysql.cj.jdbc.Driver into JVM, you can use it in subsequent programs. * / Class.forName (driverStr); / / load this class / * connection method for two different database software:-Mysql Connection con = DriverManager.getConnection ("jdbc:mysql://host:port/database", "user", "password") -Oracle Connection con = DriverManager.getConnection ("jdbc:oracle:thin@host:port/database", "user", "password"); * / conn = DriverManager.getConnection (connStr, dbusername, dbpassword); / * the commonly used Statement method-execute (): runs the statement and returns whether there is a result set. -executeQuery (): runs the select statement and returns the ResultSet result section-executeUpdate (): runs the insert/update/delete operation and returns the number of updated rows. Explained the role of the following methods * / stmt = conn.createStatement ();} catch (Exception ex) {/ / catch exceptions, learned System.out.println (ex.getMessage ()) last semester; System.out.println ("data connection failed!") ;} public int executeUpdate (String s) {/ / executeUpdate (): runs the insert/update/delete operation and returns the number of updated rows. Int result = 0; System.out.println ("--update statement:" + s + "\ n"); try {result = stmt.executeUpdate (s);} catch (Exception ex) {System.out.println ("execute update error!") ;} return result;} public ResultSet executeQuery (String s) {/ / run the select statement and return the ResultSet node ResultSet rs = null; System.out.print ("--query statement:" + s + "\ n"); try {rs = stmt.executeQuery (s) } catch (Exception ex) {System.out.println ("query execution error!") ;} return rs;} public void execQuery (String s) {try {stmt.executeUpdate (s);} catch (SQLException e) {System.out.println ("execute insert error!") ;} public void close () {try {stmt.close (); conn.close ();} catch (Exception e) {}
Only part of the code is shown above, the CSS style file in the jsp file is encapsulated locally!
The final results are shown as follows
Thank you for reading this article carefully. I hope the article "JSP dynamic how to log in and register web pages" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.