When I first made a web page, I experienced a lot of ups and downs, because the website construction is different from the development of common programming languages. For example, in Java, you only need to install JDK and download an integrated development environment such as eclipse to start development. However, the development of websites involves multiple languages and multiple software. Therefore, it is really scratching your head at the beginning. However, if you can make a good arrangement, it will not be that difficult.
When a friend asks me about the ACCESS database connection to the website, I will take the ACCESS database as an example to describe the website development process in detail. Of course, there are a variety of development processes. I am here to give you some advice. I will try my best to explain the following process and try to make everyone understand that it is not that difficult for you to be scared by such a long length.
First, let's take a look at the global situation to see what the website needs to do.
This is the basic work involved in website construction.Website Construction Process:
(1)Use Notepad ++ and Dreamweaver to compile webpages(You can use Notepad directly, but it may be quite time-consuming during a lot of development ~). The web page uses the static Language HTML, style sheet CSS, script language JavaScript, Dynamic Language JSP, PHP, ASP, and so on. In general, JSP development (the legendary J2EE) uses my eclipse integrated development environment, while ASP development uses Microsoft Visual Studio.
(2) After the webpage is compiledSet up servers and place all the web pages in the corresponding folder of the server software(For example, Tomcat is a webapps folder ). In order to run the server software properly, sometimes some configuration or installation is required. If you use the Tomcat server software, you must first install the Java JDK.
(3)Data on webpages is generally stored in databases.. JSP and PHP are commonly used in MySQL databases, ASP is commonly used in SQL Server databases, and important data of financial institutions such as banks is generally stored in Oracle databases.
The following describes the website development process through a simple logon interface.
(1) Compile a webpage
1 download notepad ++ (http://notepad-plus-plus.org/download/v5.9.3.html) and install.
After the installation is complete, open notepad ++ and create the login. jsp file. On the editing page, enter the following code:
<% @ Page contenttype = "text/html; charset = gb2312 "%> <HTML>
If you use eclipse or my eclipse for development, you need to configure the JDK environment variable:
(1) Right-click the "my computer" icon on the desktop (Vista and win7 are "computer"), select "properties", and then select "Advanced System settings ", select the label "advanced" and click "environment variable" at the bottom ".
(2) APPEND "C: \ Program Files \ Java \ jdk1.6.0 _ 27 \ bin" C: \ Program Files \ Java \ jre6 \ bin "(note: this is the path where I installed JDK, check the position of the JDK and JRE bin folders installed by yourself. Separate the contents with the semicolon (;) and click "OK.
(2) set up server software
1 first install Java JDK (http://www.oracle.com/technetwork/java/javase/downloads/index.html)
Although Java 7 is the latest version, we still use Java 6 for the sake of insurance.
Click Download of JDK. On the New Page, Select accept Oracle protocol (accept), download JDK for Windows x86, and install it.
2 download Tomcat server software (http://tomcat.apache.org/download-70.cgi)
Download is free of installation version of Tomcat, need to make the corresponding configuration as follows (the configuration process refer to the Web http://www.huomo.cn/sysapp/article-3582.html ):
(1) In the bin folder of the tomcat installation directory (C: \ apache-Tomcat-7.0.21 \ bin), find startup. BAT and shutdown. bat, right-click and use NotePad to open them, and add the following two lines at the beginning of the two files:
Set java_home = c: \ Program Files \ Java \ jdk1.6.0 _ 27
Set catalina_home = c: \ apache-Tomcat-7.0.21
(Note:
Set java_home = JDK directory
Set catalina_home = the Tomcat directory or % Cd % after decompression)
In this way, you can double-click STARTUP. BAT to run the server and double-click shutdown. BAT to close the server.
(2) modify \ conf \ tomcat-users.xml file:
Add it to the <tomcat-users> label
<Role rolename = "manager"/>
<Role rolename = "admin"/>
<User Username = "admin" Password = "admin" roles = "Admin, Manager"/>
In this way, you can use the Tomcat management interface.
(3) add tomcat to the service
A. modify the service in the bin directory. BAT file: Find set catalina_home = % Cd %. If you have never installed tomcat, or make sure that services. MSC starts the Service Manager to check that there is no Apache Tomcat System Service. Now you can go to step 2. Otherwise, find the following lines:
(A) Set SERVICE_NAME = tomcat5
"Tomcat5" is changed to the service name you need. This will be the service name that will be operated in the future using net start/stop.
(B) Set pr_displayname = Apache Tomcat
Change "Apache Tomcat" to the desired service name, which will be displayed in the Service Manager.
(C) Set pr_description = Apache Tomcat server-
It doesn't matter whether this line is changed. It is the service description. Let's decide based on your preferences.
B. Run cmd to open the console, enter the Tomat directory/bin folder, and enter the following command to run.
Service. Bat install
Program prompt: the service 'tomcat 5 (or SERVICE_NAME after you modify it) 'has been installed indicates that the Service tomcat has been installed successfully.
By the way, running service. Bat remove can remove the service.
C. here, the service is successfully added and services are run. MSC, you can see the added service. By default, the service runs manually. In its properties, change the Startup Type to "automatic ", after the machine is started, Tomcat will be started in the background.
Note: In this example, do not perform the following two steps (2) (3. Of course, if the above configuration steps are too complex, we can directly download the installed version of Tomcat:
(4) open a browser and enter http: // localhost: 8080 in the address bar. If you can see the welcome page of Tomcat, the installation and configuration are successful.
3. Create a new file named testdbunder the Tomcat web folder and copy the created login.html and testdb. jsp files to it. Open the browser and enter http: // localhost: 8080/testdb/login. jsp in the address bar. We can see the logon interface:
(3) create a database
1. Open Access 2003 and click "file"> "new ". A new window appears on the right of the screen, including some options. Select "null Database". In the dialog box that appears, name the database testdb. MDB and click "CREATE ".
2. In the pop-up edit box, click "create table with designer ":
Enter the user and password in the "field name" of the table, set "Data Type" to "text", and set "no" in the "allow null strings" section below ".
Select User, right-click and select "primary key", so that the user field can be set to "primary key ".
In the upper-right corner of the current dialog box, a prompt box is displayed, indicating whether to save the Design Modification for table 1. Click Yes. In the displayed dialog box, name the table "usertable ".
3. Double-click usertable in the figure and enter two records in the table: "Apple, 123" and "banana, 321", representing the user's apple password) the password is 123 and banana is 321.
In this way, the sample database we need is successfully created.
(4) establish connections between webpages and databases
The database stores valid user names and their corresponding password information. Now we will establish a connection between the website and the database. When we click Login login attempts in the webpage, the webpage login.html calls testdb. jsp and queries the database with the input user name to obtain the password corresponding to the user name. Then, check whether the Password Matches the password just entered on the webpage. If yes, the message "Logon successful" is returned. Otherwise, the message "User Name or Password error, Logon Failed" is returned.
1. Open "Control Panel" in the "Start" menu and find "Data Source ODBC" in "Administrative Tools ".
Click "add" under the "user DSN" tab ".
Select Microsoft Access driver and click "finish ".
In the displayed dialog box, enter the data source name testdbodbc and select the created database testdb.
2 With notepad ++ new file testdb. jsp (also stored in testdb webapps directory), enter the following code (refer to the http://www.jb51.net/article/6742.htm
And http://developer.51cto.com/art/200909/149734.htm ):
<% @ Page contenttype = "text/html; charset = gb2312" %> <% @ page import = "Java. SQL. * "%> <HTML> <body> <% Try {class. forname ("Sun. JDBC. ODBC. jdbcodbcdriver ");} catch (classnotfoundexception e) {out. print (E);} Try {string url = "JDBC: ODBC: testdbodbc"; string user = request. getparameter ("user"); out. print (User + ","); string Password = request. getparameter ("password"); connection conn = drivermanager. getconnection (u RL, "testdbodbc", "jsp.com.cn"); statement stmt = Conn. createstatement (); resultset rs = stmt.exe cutequery ("select password from usertable where user = '" + User + "'"); If (! Rs. Next () Out. Print ("sorry, your username or password is incorrect. Login Failed ~ "); Else {If (Rs. getstring (1). Equals (password) Out. Print (" Congratulations! Login successful! "); Else out. Print (" sorry, your username or password is incorrect. Login Failed ~ ");} Rs. close (); stmt. close (); Conn. close ();} catch (exception ex) {out. print (Ex) ;}%> </body>
3. Open your browser, enter http: // localhost: 8080/testdb/login. jsp in the address bar, enter the user name Apple and password 123, and click "Log On". The result is as follows:
Enter the incorrect user name app and password 123 (or you can enter another wrong user name and password) and click "Log On". The result is as follows:
Now, we have finished connecting a simple web page to the access database!
For more information, visit my personal blog: Coffee Hut http://warmcafe.info