Java web notes

1. What are the advantages and disadvantages of the two models of web development model we use?
The b/sc/s
bs browser/server model is a network structure model that emerged after the advent of the web. This model unifies the client and allows the core business processing to be completed on the server. You only need to use your computer or mobile phone. Just install the browser.
The bs browser/server model is a network structure model that emerged after the advent of the web. This model unifies the client and allows the core business processing to be completed on the server. You only need to install a browser on your computer or mobile phone. Up.
b/s advantages: low cost, zero maintenance of the client, high security
Disadvantages: heavy load, distributed applications, broadband bandwidth
2. What is the role and characteristics of http?
http: Hypertext Transfer Protocol
Stateless transmission status based on request and response The
difference between Http and Https /
1 Transmission information security is different Http is a hypertext protocol, information is a clear text protocol Https is a secure SSL encrypted transmission to ensure the security of transmission
2, The connection method is different. Http protocol: Http connection is very simple. Stateless Https protocol: It is encrypted by SSL+Http component.
3 ports are different: Http is 80 Https is 443.
4 Certificate application methods are different. Http protocol: Free application for Https protocol: Need to go to CA to apply for a certificate, generally there are fewer free certificates.
3. The execution process of the servlet?
The url→name→name→class→get or post
three-tier system in action→xml
Data layer
stores a large amount of data information and data logic, completes data-related security, integrity control, data consistency, and concurrent operations
Middle layer
All application systems, application logic, and control are here.
Presentation layer
refers to the user interface, so that end users can easily access information without any training.

The difference between get and post
"1.Get is insecure, because during the transmission process, data is placed in the requested URL; all operations of Post are invisible to the user. 2. The amount of data transmitted by Get is relatively small. Small, this is mainly because it is limited by the length of the URL; the amount of data transmitted by Post is large, and it is generally unrestricted by default."
The difference between request forwarding and redirection
Redirection:
1. It can be understood as a client behavior, a client When a request is initiated, the server will give a response, but this response contains the address of the server-side handler that the client needs to access next time. If the client initiates the request again, the processing result will be obtained, which means that the redirection client at least initiated Two requests

2. When redirecting to the page is used, the redirected path should be displayed in the path bar of the client. The client can observe the change of the page address, and the redirection is when the client has made at least two visits. request
illustration:
Insert picture description here
forwarding the request:
1. the server-side behavior will be appreciated, the client initiates a request, the request may be transmitted multiple times across the server side, but they are transferred by the handler server to another handler, the client The end does not need to initiate a second request. No matter how many processing procedures this request has gone through, it will always be the same request, which means that every processing procedure that the data in this request has gone through can be used.

2. What is passed in the middle is the request of its own container, and the path bar of the client shows the path of the first visit. The client does not feel that the server has forwarded it, and the request forwarding client only made one request.

Diagram
Insert picture description here

Four nine built-in objects and scope of
the JSP predefined total of nine such objects, namely: request, response, session, application , out, pagecontext, config, page, exception
four scopes
page range: only A page retains data (javax.servlet.jsp.PageContext (abstract class))
Request scope: Only save data in one request (javax.servlet.httpServletRequest)
Session scope: Save data in a session, only for a single user ( javax.servlet.http.HttpSession)
Application scope: save data in the entire server, shared by all users (javax.servlet.ServletContext)

Nine built-in objects
1. request object The
request object is an object of type javax.servlet.httpServletRequest. This object represents the client's request information, and is mainly used to accept data transmitted to the server through the HTTP protocol. (Including header information, system information, request method and request parameters, etc.). The scope of the request object is a request.
2, the response object
response represents the response to the client, mainly to pass the object processed by the JSP container back to the client. The response object also has a scope, it is only valid within the JSP page.

3. Session object The
session object is an object related to user requests that is automatically created by the server. The server generates a session object for each user, which is used to save the user's information and track the user's operating status. The session object uses the Map class to save data, so the format for saving data is "Key/value". The value of the session object can be a complex object type, not just a string type.

4. Application object The
application object can save information in the server until the server is closed, otherwise the information saved in the application object will be valid in the entire application. Compared with the session object, the application object has a longer life cycle, similar to the "global variables" of the system.

5. Out object The
out object is used to output information in the Web browser and manage the output buffer on the application server. When using the out object to output data, you can operate on the data buffer, clear the residual data in the buffer in time, and make room for other output. After the data output is completed, the output stream must be closed in time.

6. The
pageContext object The function of the pageContext object is to obtain any range of parameters, through which out, request, response, session, application and other objects of the JSP page can be obtained. The creation and initialization of the pageContext object are all done by the container, and the pageContext object can be used directly in the JSP page.

7.
config object The main function of the config object is to obtain the configuration information of the server. A config object can be obtained through the getServletConfig() method of the pageConext object. When a servlet is initialized, the container passes certain information to the servlet through the config object. Developers can provide initialization parameters for Servlet programs and JSP pages in the application environment in the web.xml file.

8. The page object The
page object represents the JSP itself, which is only valid within the JSP page. The page implicit object essentially contains the variables referenced by the current Servlet interface, similar to the this pointer in Java programming.

9.
Exception object The function of the exception object is to display exception information, and it can only be used in the page that contains isErrorPage="true". Using this object in a general JSP page will not be able to compile JSP files. The excepation object, like all objects in Java, has an inheritance structure provided by the system. The exception object defines almost all exceptions. In Java programs, you can use try/catch keywords to handle exceptions; if there are exceptions that are not caught in the JSP page, an exception object will be generated, and the exception object will be sent to the error page set in the page instruction , And then handle the corresponding exception object in the error page.

What is the commonly used server for Java
Tomcat server

At present, the most popular Tomcat server is a sub-project of the Apache-Jarkarta open source project. It is a small, lightweight Web server that supports JSP and Servlet technology, and is also the first choice for beginners to learn and develop JSP applications.

Resin server

Resin is a product of Caucho, a very popular server that supports Servlet and JSP, and the speed is very fast. Resin itself includes a Web server that supports HTML, which makes it not only able to display dynamic content, but also the ability to display static content is not inferior, so many websites are built using Resin server.

JBoss server

JBoss is an open source, pure Java EJB server that complies with the JavaEE specification, and has good support for J2EE. JBoss adopts JML API to realize the integration and management of software modules. Its core service is to provide EJB server. It does not include Servlet and JSP web container, but it can be perfectly integrated with Tomcat.

WebSphere server

WebSphere is a product of IBM, which can be further subdivided into series such as WebSphere Performance Pack, Cache Manager and WebSphere Application Server. Among them, WebSphere Application Server is a Java-based application environment that can run on multiple operating system platforms such as Sun Solaris and Windows NT. , Used to build, deploy and manage Internet and Intranet Web applications.

WebLogic server

WebLogic is a product of BEA, which can be further subdivided into WebLogic Server, WebLogic Enterprise and WebLogic Portal series, among which WebLogic Server is particularly powerful. WebLogic supports enterprise-level, multi-level and fully distributed Web applications, and the server configuration is simple and friendly. For those users who are looking to provide all the application servers that the Java platform has, WebLogic is an ideal choice.

How does the Java stack area clear the memory

With GC garbage collection, programmers no longer need to manually control the release of memory. When the Java Virtual Machine (VM) or .NETCLR finds that memory resources are tight, it will automatically clean up the memory space occupied by useless objects (objects that are not referenced). If necessary, you can explicitly use System.gc() / System.GC.Collect() in the program to force an immediate memory cleanup. The GC function provided by Java can automatically monitor whether the object exceeds the scope, so as to achieve the purpose of automatic memory recovery. Java's GC will automatically manage it, calling the method: System.gc() or Runtime.getRuntime().gc();

A series of data operations are transaction
drop database if exists database name;
create database database name;
foreign key foreign key (field) reference main table (field)

The reflection of servict! !

Principle: Reflection is first to be able to obtain the bytecode of the reflection class in Java, and then map the methods, variables, constructors, etc. in the bytecode to the corresponding Method, Filed, Constructor and other classes.
Application: Take out the modifiers of the class, Data members, methods, constructors, and superclasses
Find out the constants and method descriptions defined in an interface.
Get and set the value of the object data member, if the data member name is determined
at runtime , it can also be done. Call the methods of dynamic objects at all times. The
Java reflection mechanism is that in the running state, for any class, you can know all the properties and methods of this class; for any object, you can call any of its methods and properties; this The function of dynamically obtained information and the method of dynamically calling the object is called the reflection mechanism of the java language.
Insert picture description here
What is synchronous and asynchronous
1. What is synchronous request:

The synchronization request means that the browser cannot do anything after the current request is sent. It must wait until the request is completed and the data is returned before executing the subsequent code, which is equivalent to queuing. The previous person has completed his own affairs, and the next person can continue. do. That is to say, when the JS code is loaded into the current AJAX, all the code in the page will stop loading, and the page is in a suspended animation state. When this AJAX is executed, it will continue to run other code pages to release the suspended suspended state (that is, when ajax returns After the data, the following function2) is executed.

Second, what is an asynchronous request?
When the request is made, the browser can continue to do anything. Ajax sending the request will not affect the loading of the page and the operation of the user. It is equivalent to two lines, each with its own , Do not affect each other.

Generally the default value is true, asynchronous. Asynchronous requests may not affect the user's experience at all. No matter the request time is long or short, users are concentrating on operating other content on the page, and will not feel waiting.

What is the difference?

Asynchronous: In asynchronous mode, when we use AJAX to send the request, there may be code to execute. At this time, the server may not respond to our request due to various reasons, but because we have adopted an asynchronous execution method, the remaining code in all functions containing the AJAX request code will continue to execute. If we pass the request result to another JS function to process, then this time is like two threads executing at the same time.

Synchronization: In the synchronous mode, when we use AJAX to send the request, there is still code to be executed in the follow-up. We also pass the server response to another JS function to process, but the code execution at this time is: no response from the server Or when the JS function that processes the response result has not finished processing the return, the remaining code of the function containing the request code cannot be executed. Just like a single thread, after the request is sent, it enters the blocking state, and the remaining code will continue to execute until it is contacted.

Use ajax to achieve data appearing in the drop-down box
Insert picture description here
Insert picture description here

Summarize the java web
directory structure
Insert picture description here
bean is the entity class. Note that the entity class should correspond to the database field. The
dao package contains the interface method
Insert picture description here
daoimpl. The implementation class of dao is placed in the package (just put one to prevent you from forgetting it when you look at it later)

Insert picture description here
What is written in the filter is to filter the coded character set and to judge whether there is a login, and then go to other pages.
Insert picture description here
Business logic layer (put a full check)
Insert picture description here

[Why use connection pool?
Normal database connection will consume time (more than 1000 milliseconds) when connecting. After the data is started and used, the user does not perform any operation. The data will be idle. If it takes time to connect, the
connection pool
can have multiple database connections inside the connection pool. After the connection is established, if the subsequent user does not use the connection, this link will be placed in the connection pool. If the user continues To access the database, the database is directly obtained from the connection pool, and there is no need to access the database server, which reduces the request to the database server. Access efficiency improvement
tool class c3p0 tool class
Insert picture description here
xml file
Insert picture description here
uses one line of code to realize the jar package that originally needed to get the attribute

Insert picture description here
Insert picture description here

When calling, you only need to write one line of the
original code
Insert picture description here
. It is troublesome to write get every time to obtain the request parameters. If you use tools, you only need to write one sentence and you can write one
Insert picture description here
line of code. However, when you write a login, you need to get a verification code. Report an error

  1. Supplement the commonly used methods in QueryRunner (function to simplify sql)
  2. query(String sql, Object[] params, ResultSetHandler rsh); query(String sql, Object params, ResultSetHandler rsh) Query method
  3. If it is a multi-table query, you can consider using map or the following
  4. update(String sql, Object params): update(String sql, Object params[]): Perform insert, update, or delete (DML) operations.
    query(String sql, ResultSetHandler rsh): execute a select query without parameters. Insert picture description here
    The ResultSetHandler interface provides a single method: Object handle (java.sql.ResultSet .rs).
    The implementation class
    ArrayHandler of the ResultSetHandler interface : converts the first row of data in the result set into an object array.
    ArrayListHandler: Convert each row of data in the result set into an array, and then store it in the List.
    BeanHandler: encapsulate the first row of data in the result set into a corresponding JavaBean instance.
    BeanListHandler: encapsulate each row of data in the result set into a corresponding JavaBean instance and store it in the List.
    ColumnListHandler: Store the data of a certain column in the result set in the List.
    KeyedHandler(name): Encapsulate each row of data in the result set into a Map, and then store these maps in a map, whose key is the specified key. MapHandler: Encapsulate the first row of data in the result set into a Map, where the key is the column name, and the value is the corresponding value.
    MapListHandler: encapsulate each row of data in the result set into a Map, and then store it in the List

Guess you like

Origin blog.csdn.net/m0_46937429/article/details/109169737