During the period of time I have been engaged in Java Web development, I have become familiar with the Java object-oriented thinking and MVC development model. The frameworks I am currently involved in are Spring, SpringMVC, Hibernate. Below, the editor of Wulin.com will compile a tutorial for you to help you learn Javaweb-related knowledge. Interested friends can refer to it.
1. Basic concepts
1.1. Related knowledge of WEB development
WEB, in English, web means the meaning of a web page, and it is used to represent resources on an Internet host for external access.
Web resources for external access on the Internet are divided into:
1. Static web resources (such as html pages): refers to the data in the web page for people to browse.
2. Dynamic web resources: refers to the data in the web page for people to browse is generated by a program, and the content you see when accessing the web page at different points in time is different.
Static web resource development technology: Html
Commonly used dynamic web resource development technologies: JSP/Servlet, ASP, PHP, etc.
In Java, dynamic web resource development technology is collectively called Javaweb.
1.2. WEB application
WEB application refers to a program for browser access, usually referred to as a web application. For example, there are multiple web resources, such as a.html, b.html....., and these multiple web resources are used to provide services to the outside world. At this time, these multiple web resources should be placed in a 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, Js files, Java programs, support jar packages, configuration files, etc.
After the web application is developed, if you want to access 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 the mapping of virtual directories.
1.3. History of WEB development
Two stages of WEB development: static and dynamic
1.4. Static WEB
*htm and *html are the suffixes of web pages. If these contents are read directly on a server now, it means that the contents of these web pages are presented to users through the web server. The process diagram of the entire static WEB operation is as follows:
In a static WEB program, the client uses a WEB browser (IE, FireFox, etc.) to connect to the server through the network (Network), and uses the HTTP protocol to initiate a request (Request), telling the server which page I need to get now, and handing all the requests to the WEB server. Then, the WEB server takes out the content from the file system (the disk that stores all static pages) according to the user's needs. Then it is returned to the client through the WEB server. After the client receives the content, it is rendered and parsed by the browser to obtain the displayed effect.
There are several disadvantages in static WEB:
1. The content in the web page cannot be updated dynamically, and the content that all users see at all times and the final effect is the same.
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 through the browser, so there is no change on the server itself.
Means to realize dynamic effects of static WEB clients:
• JavaScript
• VBScript
JavaScript is used most in actual development.
2. Static WEB cannot connect to the database and cannot achieve interaction with users.
Saving data using a database is the choice of most systems now, because the data can be easily managed in the database, and the addition, deletion, modification and search operations can be completed using 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 WEB changes from time to person", and dynamic WEB is interactive, and the content of WEB's page can be updated dynamically. The process diagram of the entire dynamic WEB operation is as follows:
In dynamic WEB, the program still uses the client and the server, and the client still uses the browser (IE, FireFox, etc.), connects to the server through the network (Network), and initiates a request (Request) using the HTTP protocol. All requests are first processed by a WEB Server Plugin (server plugin). This plugin 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 first forwards the request to the WEB Container (WEB container), connects the database in the WEB Container, takes out data from the database and dynamically pieces together the display content of the page. After pieced together the display content of the page, all the display content is handed over to the WEB server, and then sends the content back to the client browser for parsing and execution through the WEB server.
1.6. Implementation methods of dynamic WEB applications
There are many ways to implement dynamic WEB now, and the most common ones are as follows:
•Microsoft ASP, ASP.NET
•PHP
•JAVA Servlet/JSP
1. Microsoft ASP, ASP.NET
Microsoft's dynamic WEB development was relatively early, and the first one in the country was ASP. ASP adds VB scripts to the HTML language, but the standard development application should use ASP+COM. However, in reality, when developing ASP, basically hundreds of codes are written on one page, and the page code is extremely chaotic.
ASP itself has limitations on the development platform: Windows+IIS+SQL Server/Access. ASP can only run on the Windows operating system. ASP has basically been eliminated now. Now it is basically developed using ASP.NET. ASP.NET has greatly improved its performance and is developing rapidly, but it is still limited by the platform. C# language is mainly used in ASP.NET.
2.PHP
PHP is developed very fast and has powerful functions, cross-platform (the platform refers to the operating system that runs), and the code is also simple.
3.Servlet/JSP
This is the implementation language of the B/S architecture promoted by SUN (SUN has now been acquired by Oracle). It is developed based on the JAVA language because the JAVA language is simple enough and very clean.
The performance of Servlet/JSP technology is also very high. It is not restricted by the platform and can be basically used on all platforms. Moreover, it uses multi-threading processing method during operation, so the performance is very high.
SUN's earliest WEB technology launched was a Servlet program. There were some problems when using the Servlet program itself. All programs were written in JAVA code + HTML, that is, to use JAVA output statements to output all HTML code line by line. After that, SUN was inspired by ASP and developed JSP (Java Server Page). The writing effect of some JSP code is very similar to that of ASP. This can easily enable some ASP programmers to turn to JSP learning and increase market competitiveness.
2. WEB server
2.1. Introduction to WEB server
1. A web server refers to a program that resides on a computer of some type on the Internet, and is a program that can provide documents to the browser that makes the request. When a web browser (client) connects to the server and requests a file, the server processes the request and feeds the file back to the browser, and the accompanying 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 a browser running on the Internet that sends a request.
2.2. Introduction to common web servers
1. WebLogic
WebLogic is an application server produced by American bea companies. BEA WebLogic is a Java application server for developing, integrating, deploying and managing large distributed web applications, network applications and database applications. Introduce the dynamic functions of Java and the security of Java Enterprise standards into the development, integration, deployment and management of large-scale network applications. It is currently the most widely used web server, supports J2EE specifications, and is constantly improved to adapt to new development requirements. The startup interface is shown in the figure
2. WebSphere
WebSphere Application Server is a fully functional, open web application server that is a core part of IBM's e-commerce plan. It is a Java-based application environment for building, deploying, and managing Internet and Intranet Web applications. This complete set 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:
3. Tomcat
TomcatTomcat is a minimal WEB server that implements the JAVA EE standard and is a core project in the Apache Software Foundation's Jakarta project, developed by Apache, Sun, and some other companies and individuals. Because Tomcat has advanced technology, stable performance, and is open source free, it is deeply loved by Java enthusiasts and has been recognized by some software developers, and has become a popular web application server at present. Learning JavaWeb 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), which is a web server that allows publishing information on the public intranet or the Internet. ⅡS is one of the most popular web server products at present, and many famous websites are built on the ⅡS platform. IIS provides a graphical interface management tool called Internet Information Services Manager, which can be used to monitor configuration and control Internet services.
IIS is a web service component, including a web server, a FTP server, an NNTP server and an SMTP server, which are used for web browsing, file transfer, news services and email sending, respectively. It makes it easy to publish information on the network (including the Internet and local area network). It provides ISAPI (Intranet Server API) as a programming interface for extending the functions of the Web server; at the same time, it also provides an Internet database connector, which can enable query and update the database.
To learn web development, you need to install a web server first, and then develop corresponding web resources in the web server for users to access using the browser.
3. Build a JavaWeb application development environment - Tomcat server
3.1. Question: Why do you have to install a WEB server first when learning web development?
Create a web page on the local computer, which cannot be accessed by the user, but if you start the tomcat server and place the web page in the tomcat server, the user can access it. What does this mean?
1. No matter what web resources you want to access by a remote computer, you must have a corresponding network communication program. When the user comes to access, 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, developers of We application only need to pay attention to how to write web resources, rather than how resources are sent to the client, which greatly reduces the developer's development workload.
3.2. Download and install the Tomcat server
Tomcat official site: http://jakarta.apache.org
Download the Tomcat installation package: http://tomcat.apache.org/
Click [Download] to jump to the download page shown in the figure below
3.3. Start and test the Tomcat server
Start Tomcat Server
Double-click the startup.bat file in the bin directory to start the Tomcat server
Testing Tomcat Server
Open the browser and enter http://localhost:8080/. The following interface can be displayed to indicate that the installation is successful.
3.4. Tomcat startup FAQ
The reasons why the Tomcat server cannot start normally are generally the following two reasons:
1. Problem in setting JAVA_HOME environment variables
To double-click the startup.bat file in the bin directory to start the Tomcat server, the first thing to do is to set the JAVA_HOME environment variable in Windows, because the Tomcat server needs to use this JAVA_HOME environment variable to start. If the JAVA_HOME environment variable does not exist in Windows, the Tomcat server cannot be started.
Configuring JAVA_HOME variable in Window
Operation steps (win7 system): Computer → Right-click "Properties" → Advanced System Settings → Advanced → Environment Variables, as shown in the figure below:
Click "[New]" below the system variable, and a new system variable dialog box pops up. First, write JAVA_HOME in the variable name. As the name implies, the meaning of JAVA_HOME is 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 the [OK] button, and the JAVA_HOME environment variable is set as shown in the figure below: There is an additional "JAVA_HOME" variable in the system variable.
Normally, the first step in learning Java development is to configure Path environment variables. A better configuration method is to first configure the JAVA_HOME environment variable, and then use "%JAVA_HOME%" in the Path variable to refer to the value of the JAVA_HOME variable.
Therefore, this JAVA_HOME environment variable is generally configured in Window. If you forget to configure the JAVA_HOME environment variable, you can use the above method to configure it.
2. Port occupancy issues
Because the Tomcat server needs to use port 8080 by default when starting, if this port 8080 is occupied by other applications, the Tomcat server cannot start normally. The phenomenon you see is "The Tomcat server startup interface will print out an exception error message and then it will be automatically closed", as shown in the figure below:
Since the time from startup to closing of this window is very short, it is difficult for us to see the error exception information when Tomcat starts through this window. Therefore, we can generally only view the operation of the Tomcat server through the log (log) information recorded by the Tomcat server.
There is a logs folder in the root directory of the Tomcat server.
The logs folder stores Tomcat's log files. Open the logs folder and you can see the log files inside. There is a log file named "catalina.yyyy-MM-dd.log". For example, the "catalina.2014-05-17.log" log file records the operation of the Tomcat server on 2014-05-17.
The log information clearly records the operation of the Tomcat server. If the port 8080 cannot be started normally because it is occupied, the exception information shown in the figure above will be recorded. By checking the exception information, we can know why the Tomcat server cannot start normally!
Summary: When the Tomcat server cannot start normally, first check whether the JAVA_HOME environment variable is configured, and then check whether the port at the Tomcat server is occupied by other applications.
This is the end of this article about Java Web Development Introductory Book Example Analysis (Summary 1). I hope it will be helpful to you!