javaweb01-Dynamic Web page

Source: Internet
Author: User


01. Advantages of Dynamic Web pages
Dynamic Web pages are programs that run on the server side! With different users, different conditions return different results!
001. Interactivity: The Web page will be based on the user's requirements and choices and dynamic changes and real Web content!
002. Automatic Update: No need to change the page code, will automatically update the page content!
003. Randomness: When different times, different identities of users access the same page will produce different page effects!
02. Are dynamic Web pages a substitute for static Web pages?
Each has its advantages, and the choice of which page depends on the needs and content of the site's features. If the site features simple, less content, the use of static Web pages more appropriate!
Conversely, the general use of Dynamic Web pages!
03.B/S Architecture (Browser/server browser/server)
001. Under the B/S architecture, the application is completely placed on the application server and communicates with the database server through the application server, and the system interface is displayed through the browser.
002.B/S and C/s respective advantages
Advantages of B/s:
Maintenance and upgrade methods are simple. The client software must be installed and configured in the C/s architecture. If the system needs to be updated, every client must be updated!
b/S architecture, the business logic of software application is fully implemented on the server side, all the clients are only browsers, do not need maintenance! (The upgrade browser needs to be done on the client)
Maintenance personnel only need to focus on software updates for server-side software!
Advantages of C/s:
b/S interface is not C/s friendly, it is difficult to make a rich interface such as Office software.
It takes a huge amount of design cost to speed and security!
Because the interaction of B/S architecture is request/Response mode, once the data information changes, you must refresh the page to see the updated data information!
C/s architecture is generally oriented to a fixed user base, the general highly confidential information system using the B/s architecture!
b/S architecture is applicable to the publication of public information, the confidentiality of information requirements of low situation!

Workflow of the 003.B/S architecture
01. The browser receives the user's input
02. The browser sends a request to the server, waiting for the server to respond (this request is first to the application server and then to the database server!) )
03. Data processing: Servers typically use server scripting languages (Java, etc.) for database access
04. The server sends a response to the browser! (such as dynamically generated HTML pages, and the browser is rendered after rendering to the user!) )

04.URL (Uniform Resource Locator) unified Resource Locator!

01.URL is used to describe a complete description of the Web pages and other resources on the Internet address of an identification Method! (Simply said URL is the URL!) )
02. All resources on the Internet have a unique url!
The composition of the 03.URL! http://localhost/news/index.jsp
Protocol: HTTP ==> hypertext Transfer Protocol Hypertext Transfer Protocol!
HTTPS ==> Safe! Safe
This protocol supports simple request/response dialogs! The most common protocol for a Web server!

Server domain Ip:localhost

Port number:
The port is the channel for internal and external communication within the server! When accessing the server externally, you need to access it through the specified channel!
To avoid complex IP addresses, the domain name is usually used instead! For example, Baidu IP is 202.108.22.5 domain name is baidu.com

Path:
Contains two levels of meaning!
such as news/index.jsp
News refers to the context path of the Web application when it is published externally! The Web app's root directory! INDEX.JSP stands for specific resources!

05. Common Web Server (Web container)
001.Tomcat
002.JBoss
003.Jetty

Directory structure for 06.WEB applications
/: root directory, all files in this directory can be accessed by clients! (JSP html CSS js..) )
/web-inf: Store the various resources used by the application, and the directory and its subdirectories are not accessible to clients! (which includes the Web. XML Deployment Descriptor)
/web-inf/classes: Store all of the application's class files!
/web-inf/lib: Store the jar file used by the WEB app!

Note: 01. During Tomcat operation, the Tomcat ClassLoader will load the class file in the classes directory first! Then load the jar file in the Lib directory!
If a class with the same name exists under both directories, then the class in the classes directory has precedence!
02. Each Javaweb application has a core file that is Web. xml! (Save in the Web-inf directory!) )
Web. XML controls how and how the entire application behaves!
03. After modifying Web. XML, you will need to restart the server!
The <welcome-file-list> tag in the 04.web.xml file is used to set the Web app's starting access page list!
<welcome-file> to specify a specific page!
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
...
</welcome-file-list>

07.JSP Page Java Server page (Java servers-side pages)

01.JSP technology is embedded in the HTML page of the Java scripting language, and then by the application server in the JSP container to compile and execute the resulting results will be returned to the client!
The composition of the 02.JSP:

Static content
JSP directives
JSP expressions
JSP Small Script
JSP declaration
Comments and other elements are composed!

001. Static content: such as HTML text is not related to the syntax of Java and JSP!
002.JSP instruction element: <%@%>
For example, 01.page instructions, in a JSP page can be multiple page instructions! The page directive is valid only for the current page!
Properties of the page directive:
Import= "Java.util.*"
Language= "Java"
Contenttype= "Text/html;charset=utf-8"
The ContentType property tells the Web container what format/encoding to display the contents of "response" on the client browser!
02.include instructions, etc.

003.JSP Script elements:
Small script <% Java code%>
Expression <% java variable/java expression%> cannot add a semicolon at the end of an expression ";"!
Statement <%! %> is used to define methods/variables (all global!). )

004.JSP Comment: <%--comment--%> in the client browser by viewing the source code is not visible! (It's safe!) )
HTML Comments:<!--comments--View source code can be seen! (Not Safe!) )
Using annotations in JSP scripts: <%//single-line comment%> Multiline <%/* Multiline Comment */%> view source not see! (It's safe!) )

08.JSP Execution Process! *****

When the request is sent to the server, the Web container is processed through three stages!

01. Translation Phase!
When a user accesses a JSP through a browser, the JSP engine in the Web container (Tomcat) is responsible for translating the JSP into a Java file
001.jsp declares a member method in the ==> Java file!
002.jsp script ==> A piece of code in the _jspservice () method in the Java file!
003.jsp expression ==> a piece of code in the _jspservice () method in the Java file! Out.print (expression);
004. Ordinary HTML code ==> _jspservice () in a paragraph out code! Out.print ("HTML tag");

02. Compile The Stage!
The server compiles the Java file into a class file

03. Implementation Phase!
The server executes the class file!
001. First instantiate the generated Java class!
002. Invoke the instantiated object. _jspservice () output HTML to the browser!

Note: Regardless of whether the requested URL is HTML or the JSP server responds back to HTML (the process of JSP ==> HTML takes place inside the server!). )

04. The browser renders HTML data for display to the user!

Note: Once the Web container has finished translating and compiling the JSP file. The Web container will save the compiled class bytecode file in memory!
When the user requests the same JSP again, the compiled class bytecode file can be reused! and will not translate the JSP re-compiled!
This greatly improves the performance of your Web application! (The server runs the class file directly after the request!) )
However, if the JSP is modified, the Web container will be re-translated and compiled!
In summary, the JSP will be slower on the first request!



javaweb01-Dynamic Web page

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.