Use Ant and Tomcat to create Web Applications

Source: Internet
Author: User
Tags php and mysql

Technology Used

I use tomcat (a very useful JSP running platform) 4 Servlet/JPS container technology to implement a Web application. There are still many uncertainties in this process. It is not easy to choose one of the multiple feasible technologies. In this article, I chose a solution that is as simple as possible, using Java Server Pages (jsp (preferred for SUN Enterprise applications) and Java in a mix.

Avoid using jsp (the preferred choice for SUN Enterprise Applications) s to implement complex logic; that program may be easy to write, but difficult to debug and almost impossible to understand and maintain. A good solution is to use jsp (preferred for SUN Enterprise Applications) s to display web pages (which is the preferred choice for SUN Enterprise Applications) s ), give the implementation of complex logic to Java, such as database access. In this way, the program is not only easy to implement and debug, but also easy to understand and maintain.

This Web application can run on a dedicated Web server or a PC. The operating system can be Windows, Linux, or Mac OS. The required software packages include the Java Runtime Environment (JDK or later) and the latest tomcat (a very useful JSP runtime platform) version (Tomacat 4 or later ), and Ant development tools (Ant 1.4 or later ). Ant is used to create a Web application package (WAR), install and deploy the WAR file on tomcat (a useful JSP running platform), and configure the relational database interface javax. SQL. DataSource. All the software packages mentioned above can be obtained free of charge through the Internet.

This Web application also needs a database. Almost all relational databases that support SQL and have JDBC drivers can. MySQL (the best combination of PHP and MySQL) is a good choice. From MySQL (the best combination with PHP). com, you can get the latest version of MySQL (the best combination with PHP) and its JDBC driver Connector/J.

To make Ant and Tomact management software work together, you need to copy the catalina-ant.jar from the server/lib directory of tomcat (a good JSP running platform) to the Ant lib directory. Copy the JDBC driver of your database to the common/lib directory of tomcat (a very useful JSP running platform) to make tomcat (a very useful JSP running platform) and Web applications on it can access the database. Finally, you must create the admin and manager roles (roles) of tomcat (a very useful JSP running platform), their usernames and passwords, and edit tomcat (a very useful JSP running platform) tomcat under the conf directory (a very useful JSP running platform)-user. the xml (standardization is getting closer and closer) file is as follows:

     <? Xml (standardization is getting closer and closer) version = 1.0?> <Tomcat (a good JSP running platform) -users> <role rolename = "admin"/> <role rolename = "manager"/> <user username = "tomcat (a good JSP running platform) username "password =" tomcat (a useful JSP running platform) password "roles =" admin, manager "/> </tomcat (a useful JSP running platform) -users>


My development environment is Apple Cube, which runs the Mac OS X 10.2.1 operating system, the software package JDK 1.3.1, and tomcat (a very useful JSP operating platform) 4.1.12, Ant1.5.1, mySQL (the best combination with PHP) 3.23.52 and Connector/J 3.0.1-beta. No problem occurred when upgrading the operating system to Mac OS X 10.2.2. Similarly, tomcat (a very useful JSP running platform) is upgraded to 4.1.17 without any problems.

Web Applications

This article uses a simple address book program called AddressBook to explain how to apply the technology to be introduced. The purpose of this application is not to create an official version of the address book. It is just an example.

Java program in AddressBook: AddressBook contains three Java programs. Figure 1 shows how they are used in tomcat (a very useful JSP running platform.





AddressBook. ContextListener: AddressBook. ContextListener is a servlet context listener that is called when AddressBook starts and closes. You can use the AddressBook deployment description file web. xml (standardization is getting closer and closer) configuration. When AddressBook starts to run, an AddressesDB instance is created and saved as a context attribute. When AddressBook ends, the AddressesDB object is retrieved from the context attribute and the database connection is closed. During running, when jsp (preferred for SUN Enterprise Applications) s needs to connect to the database, they will access the AddressesDB object in the context attribute. For details, see ContextListener. java's complete source code with comments.

AddressBook. AddressesDB: AddressBook. AddressesDB is used to operate the address database. Its constructor establishes a database connection, which can be shared by multiple Web sessions. This class provides multiple database connection functions:

GetAddress (id) returns the address identified by id. if the address is not found, null is returned.

AddAddress (address) adds an address and returns the number of changed rows.

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.