Go: Example of Java Web Demo

Source: Internet
Author: User

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
  1. <span style=""><%@ taglib uri="Http://java.sun.com/jsp/jstl/sql" prefix= "SQL"%>
  2. <%@ taglib uri="Http://java.sun.com/jsp/jstl/core" prefix="C"%>
  3. <sql:query var="rs" datasource="Jdbc/testdb">
  4. Select Host, user, password from user
  5. </sql:query>
  6. <html>
  7. <head>
  8. <title>db Test</title>
  9. </head>
  10. <body>
  11. <h2>results</h2>
  12. <C:foreach var="Row" items="${rs.rows}">
  13. Foo ${row.host}<br/>
  14. Bar ${row.user}<br/>
  15. </C:foreach>
  16. </Body>
  17. </html>
  18. </span>

(5) Web. XML content:

XML code
  1. <span style=""><? XML version= "1.0" encoding="iso-8859-1"?>
  2. <!--
  3. Licensed to the Apache software Foundation (ASF) under one or more
  4. Contributor license agreements. See the NOTICE file distributed with
  5. This is for additional information regarding copyright ownership.
  6. The ASF licenses this file to you under the Apache License, Version 2.0
  7. (the "License"); Except in compliance with
  8. The License. Obtain a copy of the License at
  9. http://www.apache.org/licenses/LICENSE-2.0
  10. Unless required by applicable law or agreed to writing, software
  11. Distributed under the License is distributed on a "as is" BASIS,
  12. Without warranties or CONDITIONS of any KIND, either express or implied.
  13. See the License for the specific language governing permissions and
  14. Limitations under the License.
  15. -->
  16. <Web-app xmlns="Http://java.sun.com/xml/ns/javaee"
  17. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  18. xsi:schemalocation="Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "  
  19. version="2.5">
  20. <display-name>jdbc Test</display-name>
  21. <description>
  22. Tomcat Jdbc Test.
  23. </Description>
  24. </Web-app>
  25. </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
  1. <span style=""><? XML version= '1.0 ' encoding=' utf-8 '?>
  2. <tomcat-users>
  3. <role rolename="manager"/>
  4. <role rolename="admin"/>
  5. <user username="admin" password="admin" roles="Admin,manager"/>
  6. </tomcat-users>
  7. </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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.