Introduction to Java Web Development
1、 Basic concepts
1.1. Relevant knowledge of Web Development
Web, in English, web means web page. It is used to represent the resources on the Internet host for external access. Web resources on the Internet for external access are divided into:
1)、 Static web resources (such as HTML page): it means that the data for people to browse in the web page is always the same. 2) dynamic web resources: it means that the data for people to browse in the web page is generated by the program, and the contents seen when visiting the web page at different time points are different. Static web resource development technology: HTML commonly used dynamic web resource development technology: JSP / servlet, ASP, PHP, etc In Java, dynamic web resource development technology is collectively referred to as JavaWeb.
1.2. Web application
Web application refers to the program accessed by the browser, which is also commonly referred to as web application. For example, a.html, b.html Multiple web resources, which are used to provide external services. At this time, the multiple web resources should be placed in one directory, To form a web application (or web application) a web application consists of multiple static web resources and dynamic web resources, such as HTML, CSS, JS files, JSP files, Java programs, support jar packages, configuration files, etc. after the web application is developed, if you want to be accessed by the outside world, you need to hand over the directory where the web application is located to the web server for management. This process is called virtual directory mapping
1.3 web development history
Two stages of Web Development: static and dynamic
1.4. Static web
* HTM, * HTML, these are the suffixes of web pages. If these contents are directly read on a server, it means that the contents of these web pages are presented to users through the web server. The process diagram of the whole static web operation is as follows:
In the static web program, the client uses a web browser (ie, Firefox, etc.) to connect to the server through the network, Use the HTTP protocol to initiate a request, tell the server which page I need to get now, and give all the requests to the web server. Then the web server starts the file system according to the needs of the user (the disk storing all static pages) take out the content, and then return it to the client through the web server. After the client receives the content, it will be rendered and parsed by the browser to obtain the display effect.
Static web has the following disadvantages:
1. The content in the web page cannot be updated dynamically. All users see the same content and final effect all the time.
In order to make the static web display more beautiful, JavaScript can be added to complete some display effects on the page, but these effects are displayed to users on the client with the help of the browser, so there is no change on the server itself.
Means to realize the dynamic effect of static web client:
JavaScript VBScript
JavaScript is used most in actual development.
2. The static web cannot connect to the database and cannot interact with users.
Using database to save data is the choice of most systems now, because data can be easily managed in the database, and the operations of adding, deleting, modifying and querying can be completed with standard SQL statements.
1.5 dynamic web
The so-called dynamic does not mean that the page will move. The main feature is: "the page display effect of the web changes with time and people", and the dynamic web is interactive, and the content of the web page can be updated dynamically. The process diagram of the whole dynamic web operation is as follows:
In the dynamic web, the program still uses the client and server, and the client still uses the browser (ie, Firefox, etc.) to connect to the server through the network, The HTTP protocol is used to initiate requests. Now all requests are processed through a web server plug-in (server plug-in). This plug-in is used to distinguish whether the request is a static resource (*. HTM or *. HTM) or a dynamic resource.
If the web server plugin finds that the client requests static resources (*. HTM or *. HTM), it directly forwards the request to the web server, and then the web server takes out the content from the file system and sends it back to the client browser for parsing and execution.
If the web server plugin finds that the client requests dynamic resources (*. JSP, *. ASP / *. ASPX, *. PHP), it will first transfer the request to the web container (web container), connect the database in the web container, take out the data from the database, and then dynamically piece up the display content of the page. After patching up the display content of the page, Deliver all the displayed contents to the web server, and then send the contents back to the client browser through the web server for parsing and execution.
1.6 implementation means of dynamic web application
There are many ways to implement dynamic web. The more common ones are as follows:
Microsoft ASP、ASP. NET
PHP
JAVA Servlet/JSP
1、Microsoft ASP、ASP. NET
Microsoft's dynamic web development is relatively early, and ASP is the earliest and most popular in China. ASP adds VB script to HTML language, but the standard development application should use ASP + com, but in fact, when developing ASP, hundreds of codes are basically written in one page, and the page code is extremely chaotic.
ASP itself has the limitations of the development platform: Windows + IIS + SQL Server / access. ASP can only run on the windows operating system. ASP has been basically eliminated. Now it is basically used Net, ASP Net has been greatly improved in performance and developed rapidly, but it is still limited by the platform. ASP. Net mainly uses c# language.
2.PHP
PHP development is fast, powerful, cross platform (platform refers to the operating system running), and the code is also simple.
3.Servlet/JSP
This is the implementation language of B / S architecture mainly promoted by Sun company (sun has now been acquired by Oracle company). It is developed based on Java language, because Java language is simple enough and clean.
The performance of servlet / JSP technology is also very high. It is not limited by the platform, and each platform can be used basically. In addition, multithreading is used in the operation, so the performance is very high.
The earliest Web Technology launched by Sun company is the servlet program. There are some problems when the servlet program itself is used. All programs are written in the way of Java code + HTML, that is, to use Java output statements and output all HTML codes line by line. After that, Sun company developed JSP (Java server page) inspired by ASP, The writing effect of some code of JSP is very similar to that of ASP. This can easily make some ASP programmers turn to JSP to learn and increase the competition in the market.
2、 Web server
2.1 introduction to web server
1. Web server refers to a program that resides on a certain type of computer on the Internet and can provide documents to the requesting browser. When a web browser (client) connects to the server and requests a file, the server will process the request and feed back the file to the browser. The attached information will tell the browser how to view the file (i.e. file type).
2. The server is a passive program: the server will respond only when the browser running on other computers on the Internet sends a request.
2.2 introduction to common web servers
1、WebLogic
Weblogic is an application server produced by American bea company. BEA Weblogic is a Java application server for developing, integrating, deploying and managing large-scale distributed web applications, network applications and database applications. The dynamic function of Java and the security of Java enterprise standard are introduced into the development, integration, deployment and management of large-scale network applications. It is the most widely used web server at present. It supports J2EE specification and is constantly improved to meet the new development requirements. The startup interface is shown in the figure
2、WebSphere
Websphere application server is a fully functional and open web application server. It is the core part of IBM's e-commerce plan. It is a Java based application environment for establishing, deploying and managing Internet and Intranet web applications. This suite of products has been expanded to meet the needs of web application servers, ranging from simple to advanced to enterprise level. The startup interface is shown in the figure below:
3、Tomcat
Tomcat Tomcat is the smallest web server that implements the Java EE standard. It is a core project of the Jakarta project of the Apache Software Foundation. It is jointly developed by Apache, sun and some other companies and individuals. Because Tomcat technology is advanced, stable performance, and open source free, so deeply loved by Java enthusiasts and has been recognized by some software developers, has become a popular Web application server. Learning java web development generally uses Tomcat server, which supports all JSP and servlet specifications. The startup interface is shown in the figure:
4、IIS
Microsoft's web server product is Internet information services (IIS), IIS is a web server that allows publishing information on public intranet or Internet. IIS is one of the most popular web server products at present, and many famous websites are built on the platform of IIS. IIS provides a graphical interface management tool, called Internet Information Service Manager, which can be used to monitor, configure and control Internet services.
IIS is a web service component, including web server, FTP server, NNTP server and SMTP server, which are used for web browsing, file transmission, news service and mail sending respectively, It makes it easy to publish information on the network (including Internet and LAN). It provides ISAPI (intranet server API) as a programming interface to expand the functions of web server; at the same time, it also provides an Internet database connector to query and update the database.
To learn web development, you need to install a web server first, and then develop the corresponding web resources in the web server for users to access using the browser.
3、 Build a Java Web application development environment -- Tomcat server
3.1. Question: why do you have to install a web server before learning web development?
Users cannot access any web page created on the local computer, but if you start the Tomcat server and put the web page in the Tomcat server, users can access it. What does this mean? 1. If any web resource wants to be accessed by the remote computer, there must be a corresponding network communication program. When the user accesses, the network communication program reads the web resource data and sends the data to the visitor. 2. Web server is such a program, which is used to complete the underlying network communication. Using these servers, we application developers only need to pay attention to how to write web resources, rather than how to send resources to the client, which greatly reduces the developer's development workload.
3.2. Download and install Tomcat server
Tomcat official website: http://jakarta.apache.org
Download the Tomcat installation package: http://tomcat.apache.org/
Click [Download] to jump to the download page as shown in the figure below
tar. GZ file is the installation version under Linux operating system. EXE file is the installation version under Windows system. Zip file is the compressed version under Windows system. After downloading, you get a compressed package. Unzip the compressed package to complete the installation of Tomcat server
3.3. Start and test Tomcat server
Start Tomcat server
Double click Startup. Exe in the bin directory Start the Tomcat server with the. Bat file
Test Tomcat server
Open the browser and enter http://localhost:8080/ , the following interface can be displayed, indicating successful installation.
3.4. Tomcat startup FAQs
Generally speaking, there are two reasons why the Tomcat server cannot start normally:
1、JAVA_ Home environment variable setting problem
To double-click startup. Exe in the bin directory Bat file to start the Tomcat server, the first thing to do is to set up Java in windows_ Home environment variable, because this Java is required for the startup of Tomcat server_ Home environment variable, if Java does not exist in Windows_ Home environment variable, the Tomcat server cannot be started.
Configuring Java in window_ Home variable
Operating steps (win7 system): computer → right click "properties" → advanced system settings → advanced → environment variables, as shown in the figure below:
Click "[new]" under the system variable to open a dialog box for creating a new system variable. First, write java_home in the variable name. As the name suggests, java_home means the installation path of JDK, and then write the installation path of JDK in the variable value. For example, the variable value set here is "D: \ program files (x86) \ Java \ jdk1.7.0". After setting the variable value, click Click OK to set the java_home environment variable, as shown in the following figure: there is an additional "java_home" variable in the system variable.
Normally, the first step in learning java development is to configure the path environment variable. A better configuration method is to configure Java first_ The home environment variable, and then use "% java_home%" in the path variable to reference Java_ The value of the home variable.
So this Java_ The home environment variable is generally configured in window. If you forget to configure Java_ Home environment variable, you can configure it in the above way
2. Port occupation
Because the Tomcat server needs to use port 8080 by default when it is started. If this port 8080 is occupied by other applications, the Tomcat server cannot start normally. The phenomenon is that "the Tomcat server startup interface will print an abnormal error message, and then it will shut down automatically", as shown in the following figure:
Because the time from Startup to shutdown of this window is very short, it is difficult for us to see the error and exception information during Tomcat startup through this window. Therefore, we can only view the operation of Tomcat server through the log information recorded by Tomcat server.
There is a logs folder under the root directory of the Tomcat server,
The logs folder stores Tomcat's log files. Open the logs folder to see the log files in it, including a log file named "Catalina. Yyyy-mm-dd.log". For example, "Catalina. 2014-05-17. Log" log file records the operation of Tomcat server on 2014-05-17.
Open Catalina 2014-05-17. Log file. Look at the log information in it,
The log information clearly records the operation of the Tomcat server. If the 8080 port is occupied and cannot be started normally, the exception information shown in the above figure will be recorded. By viewing the exception information, we can know why the Tomcat server cannot be started normally!
Summary: when the Tomcat server cannot start normally, first check whether Java is configured_ The home environment variable, and then check whether the port when the Tomcat server starts is occupied by other applications.