Java foundation

xiaoxiao2021-03-06  39

1. What built-in objects do you have JSP? What is the role?

(1) REQUEST object for the HTTPSERVLETREQUEST class

Role: Represents the request object, mainly for accepting the client to transmit data from the HTTP protocol connection to the server side.

(2) HTTPSERVLETRESPONSE class response object

Role: Representing the response object, mainly used to send data to the client

(3) OUT objects of JSPWriter class

Role: Mainly used to output data to the client;

OUT base class is JSPWriter

(4) SESSION objects for the HTTPSession class

Role: Mainly used to save each user information, associated with requests;

Session status maintenance is a problem that web application developers must face.

(5) Application object of the ServletContex class

Role: Mainly used to save user information, the operating environment of the code snippet;

It is a shared built-in object that shares an Application object in a container, so the information whose saved is shared by all users.

(6) PageContext objects of PageContext

Role: Manage web properties, context for the JSP page package page, manage access to named objects in a special visible section in JSP, and its creation and initialization is done by the container.

(7) Config objects for the ServletConfig class

Role: Code fragment configuration object, represents the configuration of the servlet.

(8) Object class Page (equivalent to this) object

Role: Processing the JSP page, an instance of the Object class, refers to an instance of the JSP implementation class, that is, it is also a JSP itself, only in the JSP page range is legal.

(9) EXCEPTION

Role: Handling errors and abnormalities occurring during execution of JSP files

--------------------------------------------------

2, describe the lifecycle and basic architecture of the servlet.

1. When the server is started, the servlet is loaded by the server when the servlet is requested or configured by the client.

The loading of the servlet can be implemented from a local or remote address by using a custom Java class load tool (allowed to be automatically servlet overloaded). This step is equivalent to

Class C = Class.Forname ("com.sourcestream.myservlet);

The term loading refers to the simultaneous load and initialization of the servlet simultaneously.

2. The server creates a servlet class instance to serve all requests. With multi-thread, you can serve in parallel requests by a single servlet instance. Only five exceptions are because of the servlet for the SingLethreadModel interface, this, the server creates an instance pool and selects one to serve each new request. This step is equivalent to the following Java code:

Servlet S = (servlet) c.newinstance ();

3. The server calls the subscript of the servlet. It is used to ensure completing the previous execution process for the first time requesting servlet. If the servlet creates multiple servlet instances, the init () method is called for each instance.

4. The server constructs a servletRequest or httpservletRequest object from the data included in the customer request, and also constructs a servletResponse or httpservletResponse object to return response to provide methods. Its parameter type depends on whether the servlet extension GenericServlet or httpservlets. (Note: This step will not occur if the server does not receive the request for this servlet, this step will not happen to the following 5 - 7 steps.) 5. The server calls the Service () method (for httpservlets, service () will call more specific methods: DOGET () or dopost ()), in which the structured object is transmitted as a parameter. When the parallel request arrives, multiple service () methods can run in separate threads simultaneously. (Unless servlet achieves a SingLethReadModel interface)

6 Analyze the Servletreuest or HttpServletRequest object. The service () method handles the customer's request. And call the ServletResponse or HttpServletResponse object to respond.

7. If the server receives another request to the servlet, this processing is repeated from 5 steps.

8. Once the servlet container detects a servlet to be uninstalled, this may be because it is necessary to recycle resources or because it is being closed, the server will call servlet's desk after all servlet's service () threads (or after the server specifies time) DESTROY ( )method. The servlet can then collect cleanup in a useless storage unit. The servlet container does not need to specify a time for retain a servlet.

The above 8 steps are the life cycle of the servlet.

-------------------------------------------------- -----------

3, many threads have several implementation methods, what is it?

Synchronize several implementation methods, what is it?

(1) By inheriting Class Thread or implementing Runnable interface, we can implement multithreading

(2) Realize resource synchronization via Synchronized

2.1 lock sign

2.1.1 Each object has a marker lock. When a thread of the object accesses a SYNCHRONIZED data (including functions) of the object, this object will be "lock", so it is not possible to be called (including functions) (because the current thread takes away) The "Lock Sign" of the object). Only the current thread accesss the synchronized data it wants to access, releases "Lock Sign", and other threads of the same object can access Synchronized data.

2.1.2 Each Class also has a "lock sign". For SYNCHRONIZED Static data (including functions), you can lock the entire Class to avoid STATIC data.

2.2 Non-Static Synchronized Data can only be accessed simultaneously in purebred the same object, and the threads of different objects can be accessed simultaneously.

2.3 The "Lock Sign" and Class of the Object "Lock Sign" is independent of each other

(3) Synchronization optimization

1) SYNCHRONIZED BLOCK

Synchronized (Reference) {do this}

Reference is used to specify "The Lock Sign of an Object" is synchronously controlled to "code" in the brace ".

Reference: http://www.yesky.com/softchannel/72342371961929728/20031122/1747065.SHTML ----------------------------- -------------------------------------------------- -------

4, public private protected and non-written differences?

Private

,

protected

,

public

Is a member of a member (member variable, member method) access modifier

Access Right Indicates which types of access to members in this class

For example, members who are modified by private are not allowed to be accessed by other classes, only allowed to be accessed by this category; and members modified by publications allow for all types of access

Table 7-1 Access to class members

Accessed by this Class Access to Subsets Access to the same package Access to all types Access Private Allow Not allowable not allowing Protected Allow Allow Allow PUBLIC Allow Allow Allow Allow Wriendly Allow Not Allow Allow Allow Allow

-------------------------------------------------- ----------------

5. Use Java to implement the database query (write a complete program).

Class .forname (Drive Class);

Connection conn = drivermanger.getConnection (URL, UserName, Password);

Statement Stmt = Conn.createStatement (SQK);

ResultSet RS = stmt.executeQuery ();

While (Rs.Next)

{

Rs.getstring ();

.......

}

Oh ~~~

I am looking at it myself!

转载请注明原文地址:https://www.9cbs.com/read-63704.html

New Post(0)