JDK installation is simple, if you have a problem, you can send me an email, or visit my homepage, http://www.bcxy.com/sdl1, install Tomcat
Make sure that JDK is installed, refer to the Tomcat for Window's installation wizard, basically directly installed, note: Enter the management username and password when installing, this is the username and password used later, remember.
2, install mysql
The default is installed.
3, use Tomcat's Web Management Application Configure Data Source
Start the Tomcat server, open the browser, enter http: // localhost: 8080 / admin / (where localhost is the name server or the host), enters the management interface login page, at this time, please enter the user name that is required to enter when installing. Password, log in to the management interface,
Select Resources-Data Sources to enter the configuration data source interface, select Data Source Actions -> Select CREATE New Data Source to enter the configuration details interface, the content is as follows:
JNDI NAME: JDBC / MySQL
Data Source URL: JDBC: MySQL: // Localhost: 3306 / CS
JDBC Driver Class: com.mysql.jdbc.driver
User Name: root
PASSWORD: *********
Max. Active Connections: 4
Max. Idle Connections: 2
Max. Wait for Connection: 5000
Validation Query:
The information requested by JNDI Name is required, in which other other can be filled in according to your needs. For example, the content of the Data Source URL may be: jdbc: mysql: // ip or name / databasename, where DatabaseName is your database name, IP is the IP or name of the server where your database is located. Finally click Save-> Commit Change. So your basic data of your data source is half configured.
4 (This step can not be done, just check it) Modify the configuration file corresponding to your reference under Web.xml and% Tomcat_Home% / Conf / Catalina / localhost
Open% tomcat_home% / conf / web.xml, add the following in front of web-app>::
resource-ref>
Note that the content fill in RES-REF-NAME is consistent with the JNDI Name name mentioned above.
Enter% Tomcat_Home% / Conf / Catalina / LocalHost, find your web application corresponding to the .xml file (below with my web directory structure), such as MyWeb.xml, and add the code under this file:
5, other considerations
Don't forget the JDBC driver mysql-connection-bin.ja must be placed to Tomcat's corresponding directory, your JDBC driver may be high, but as long as you can correspond to the mysql used Yes, because I found that the version of the JDBC driver that does not support 4.0. * Version of the MySQL database, it is recommended to place under the% Tomcat_Home / Common / LIB and the application of Web-INF / LIB. What is the difference between the two? In fact, I will understand that Common / lib is all applications that can be used by all applications.
Restart your Tomcat service.
6, write test code
Create a Test.jsp file in the application's directory, the code is as follows:
"http://www.w3.org/tr/rec-html40/strict.dtd">
<% @ Page Import = "java.sql. *"%>
<% @ Page Import = "javax.sql. *"%>
<% @ Page Import = "javax.naming. *"%>
<% @ Page ContentType = "text / html; charset = GB2312"%>
<%
Out.print ("My Test Start");
Try {
Context initContext = new InitialContext (); Context envContext = (Context) initContext.lookup ( "java: / comp / env"); DataSource ds = (DataSource) envContext.lookup ( "jdbc / mysql"); con = ds.getConnection ();
Statement Stmt = conn.createstatement ();
// Tip: Users must be a table for the database,
// The database mentioned in the Data Source URL configuration herein is included in the database.
String strsql = "select * from users";
ResultSet RS = Stmt.executeQuery (strsql);
While (rs.next ()) {
Out.print (Rs.getstring (1));
}
Out.print ("My Test ends");
}
Catch (Exception EX) {
Out.print ("Exception Exceptions, information is:" ex.getMessage ());
EX.PrintStackTrace ();
%>
hEAD>
body>
html>
operation result:
My test starts 12345678 My test ends because my RS.GetString (1) is stored in the database 12345678
7, summary
Thank Jemlee2002 Note: In H: / Webspp / MyWeb / Web-INF / LIB / Under is JSTL's JAR file, Classes is bean, H: / Webspp / MyWeb / Web-INF / Lower (refer to me Alternative: Install JSTL in Tomcat and 8 TLD files. Mysql's drive is placed in% Tomcat_Home% / Common / Lib / under% Tomcat_Home% / CONF / CATALINA / LOCALHOST / Under the
Context>