Java Web basics: Fifth, manual web application Construction

Source: Internet
Author: User

 

Create a web applicationProcess: Create application directory, create WEB-INF folder, create web. XML document, create classes folder, create lib folder, create welcome interface, start server, access program. Create a web application directoryEach web application corresponds to a root directory, where all files related to the application are located. Generally, the root directory name is the application name. In this book, The Application name is determined as bookstore. The server must be able to find the root directory of the application to run the web application, that is, to deploy the application to the server. There are two ways to complete the deployment. The first way is to complete the deployment through the configuration file, which can be configured in the configuration file, usually through the management tool. Another way is to let the server automatically load, so that web application developers can work simply. In order to allow the server to automatically load the application, you need to put the application under a specific directory. In tomcat, you can place the application under the webapps under the Tomcat directory. Create a WEB-INF folderEach web application contains a WEB-INF folder that stores some special files. Files stored in this folder are usually not directly accessible from the client. In the WEB-INF directory, there are mainly the following types of files: N Configuration Files: common XML files, TLD files, properties files (attribute files ). Class N files: External class libraries used by the system, or class files compiled by the System Create a web. XML documentThe Web. XML document is located in the WEB-INF folder, and each web application should correspond to a web. XML document. This document describes the configuration of a Web application. This file usually does not need to be written manually. On the one hand, it is prone to errors and on the other hand, it is time-consuming. If the integrated development environment is used, the file is automatically generated in the integrated development environment. If you create a web application manually, you can copy one from another Web application and modify it. Modify it to the following format. <? XML version = "1.0" encoding = "ISO-8859-1"?> <Web-app xmlns = "http://java.sun.com/xml/ns/j2ee" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_5.xsd" version = "2.5"> </Web-app> Create a classes folderThe classes folder is located in the WEB-INF folder where all class files related to this Web application should be placed. Note: When the class is placed in the classes folder, you need to create a folder corresponding to the relevant package. For example, there is a class dbbean where the package is beans, you should store the file as follows: WEB-INF/classes/beans/dbbean. some Web applications of class will use the properties file to save some configuration information, which also needs to be placed in the classes folder. If there are multiple property files, you can also create subfolders for the property files based on their categories, just like creating a package for the class. Create lib folderLib folder is located in the WEB-INF folder, lib folder is also used to store class files, but these files exist in the form of a compressed package. If the class file does not exist in the form of a compressed package, it should be placed in the classes folder. When some external functions are used in Web applications, these functions usually exist in the form of a. jar file. These packages should be placed in the lib directory. Create welcome pageEach website is composed of a large number of files, but no matter what website you visit, users seldom enter the file name, because they usually do not know the name of the file on the website. Websites usually have a welcome page. When users visit a website, they usually see a welcome page. Figure 1.22 is the welcome page of Sina: we only need to enter the http://www.sina.com.cn when accessing. The user can see the welcome page of the website. The common welcome Interface Name Is index.html?index.htm or index. jsp. If you want to configure the default welcome page for the web application, you can. add the following code to the xml configuration file: <welcome-file-List> <welcome-File> index. JSP </welcome-File> </welcome-file-List> the process of creating a web application is actually the process of creating a large number of JSP files. The suffix of A jspfile is usually .jsp. if the Java code is not included and the suffix is an ordinary HTML file, you can use .htm).html. The code in the file is mainly composed of HTML code, embedded Java scripts, and a large number of JSP syntaxes. In terms of function, a file mainly includes two functions: the information to be displayed and the format used to display the information. Generally, HTML code is used to control the format of the content to be displayed. Java code and JSP usage are used to control what information to display. The file creation process also contains two processes: first, determine the page format based on the information to be displayed, and then use JSP code and Java code to control the content to be displayed. The code for the welcome page of the online bookstore is as follows: <% @ page pageencoding = "GBK" %> <HTML> Start the serverYou must start the server before accessing the JSP program. The server startup process is as follows: [start] à [Apache Tomcat 6.0] à [configure Tomcat]. The server startup page is displayed. on this page, click [start] to start the server. Tip: You can directly start the server in the file directory and use tomat6.exe tomcat6w.exe In the subdirectory of the tomcat installation directory. Access JSP programWhen accessing JSP programs, you need to provide the following information: N protocol, usually HTTP. N host, the IP address or name of the server. Local virtual addresses or real addresses can be used for local applications. Localhost is the name of the local Vm, and 127.0.0.1 is the IP address of the local VM. Port n. The default value is 80. The default value is 8080 when Tomcat is used for development. N web applications. Each web application corresponds to a path. The default path name is the same as the Web application folder name. The application name in this instance is bookstore. N file. You must specify the name of the file to be accessed. The file name in this instance is index. jsp. To access the welcome interface above, open the browser and enter the address. The address can be written in multiple ways: http: // localhost: 8080/bookstore/index. jsphttp: // 127.0.0.1: 8080/bookstore/index. jsphttp: // 192.168.1.3: 8080/bookstore/index. jsphttp: // lixucheng: 8080/bookstore/index. the first two types of JSP are virtual local hosts, and the last two are IP addresses and host names. In actual applications, access is primarily based on domain names. If the welcome interface is set, the file name following it can be omitted. For example, the first address can be written as follows: http: // localhost: 8080/bookstore: Lecture 4 Java Web Application Document StructureNext Lecture: 6. jsp operating principlesLi xucheng csdn blog: Why? U= 124362 & C = 7be8ba2b6f3b6cc5

 

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.