http://quqtalk.iteye.com/blog/360699
Java has been in development for two years, but because of the work of the relationship, the Java Web is still a freshman. Today I made a simple demo of the Java Web, the summary of this demo is as follows.
Environment:
Jdk:1.5.0_12-b04
tomcat:apache-tomcat-6.0.18
Mysql:mysql-5.1.32-win32
These software can be downloaded from the respective official website.
Demo Production process:
(1) Configure the MySQL data source in Tomcat.
Modify the context.xml in the $catalina_home/conf directory to add the following configuration:
<resource name= "Jdbc/mysqldb" auth= "Container" type= "Javax.sql.DataSource"
Maxactive= "maxidle=" maxwait= "10000"
Username= "root" password= "" Driverclassname= "Com.mysql.jdbc.Driver"
Url= "Jdbc:mysql://localhost:3306/mysql?autoreconnect=true"/>
Here is a learning point, that is, the resource element of the various attributes of what is the meaning of each?
(2) Put the JDBC-driven jar package containing MySQL into the $catalina_home/lib directory.
(3) in the $catalina_home/webapps directory, create a new TESTJDBC directory, TESTJBDC directory structure
+testjdbc/
|
|--+web-inf/
| |
| |--+lib/
| |
| |--+web.xml
|
|--+index.jsp
(4) Contents of index.jsp:
HTML code
- <span style=""><%@ taglib uri="Http://java.sun.com/jsp/jstl/sql" prefix= "SQL"%>
- <%@ taglib uri="Http://java.sun.com/jsp/jstl/core" prefix="C"%>
- <sql:query var="rs" datasource="Jdbc/testdb">
- Select Host, user, password from user
- </sql:query>
- <html>
- <head>
- <title>db Test</title>
- </head>
- <body>
- <h2>results</h2>
- <C:foreach var="Row" items="${rs.rows}">
- Foo ${row.host}<br/>
- Bar ${row.user}<br/>
- </C:foreach>
- </Body>
- </html>
- </span>
(5) Web. XML content:
XML code
- <span style=""><? XML version= "1.0" encoding="iso-8859-1"?>
- <!--
- Licensed to the Apache software Foundation (ASF) under one or more
- Contributor license agreements. See the NOTICE file distributed with
- This is for additional information regarding copyright ownership.
- The ASF licenses this file to you under the Apache License, Version 2.0
- (the "License"); Except in compliance with
- The License. Obtain a copy of the License at
- http://www.apache.org/licenses/LICENSE-2.0
- Unless required by applicable law or agreed to writing, software
- Distributed under the License is distributed on a "as is" BASIS,
- Without warranties or CONDITIONS of any KIND, either express or implied.
- See the License for the specific language governing permissions and
- Limitations under the License.
- -->
- <Web-app xmlns="Http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemalocation="Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
- version="2.5">
- <display-name>jdbc Test</display-name>
- <description>
- Tomcat Jdbc Test.
- </Description>
- </Web-app>
- </span>
(6) in the Testjdbc/web-inf/lib directory to put Jstl Jstl.jar and Standard.jar, in Tomcat document, it is recommended to use 1.1.x release, can be from HTTP// JAKARTA.APACHE.ORG/SITE/DOWNLOADS/DOWNLOADS_TAGLIBS-STANDARD.CGI get.
(7) mysqld--console start MySQL.
(8) $CATALINA _home/bin directory, Startup.bat start Tomcat.
(9) In the browser address bar typing http://127.0.0.1:8080/testjdbc/can be seen from the MySQL library, the user table out of the data.
(10) on the Tomcat homepage can access the Management page, http://127.0.0.1:8080/manager/html, the first entry requires the user name and password, tomcat installation, there is no user name and password, modify the $catalina_ Home/conf/tomcat-users.xml:
XML code
- <span style=""><? XML version= '1.0 ' encoding=' utf-8 '?>
- <tomcat-users>
- <role rolename="manager"/>
- <role rolename="admin"/>
- <user username="admin" password="admin" roles="Admin,manager"/>
- </tomcat-users>
- </span>
On the admin page, fill in the User name password box to go to the admin page and see all the apps that have been deployed admin/admin.
Go: Example of Java Web demo