Java Web face question 2

Source: Internet
Author: User
Tags java web

1. servlet life cycle, and tell the difference between servlet and CGI

After the Web container loads the servlet and instantiates it, the servlet life cycle begins, the container runs its Init method for the servlet initialization, the request arrives when it runs its service method, the service method is dispatched automatically, and the Doxxx method that runs the request (DoG ET, doPost), calling its Destroy method when the server decides to destroy the instance. The difference with CGI is that the Servlet is in a server process, it runs its service method in a multithreaded manner, one instance can run multiple requests, and its instances are generally not destroyed, and the CGI generates new processes for each request, which is destroyed after the service is finished, so it is less efficient than Servlet.

2. The difference between forward and redirect

Forward is the steering of the control, the server requests the resource, the server requests the URL of the destination address directly, reads the response content of that URL, and then sends the content to the browser. The browser does not know where the server sends the content, so its address is still the original address. Redirect is the server side according to logic, send a status code, tell the browser to request a new address, the browser address bar is displayed on the new request address. Forward more efficient. In some cases, if you need to use resources on other servers, you must use the redirect

3. The difference between dynamic include and static include in JSP

Dynamic include is implemented with Jsp:include action: <jsp:include page= "TEST.JSJP" flush= "true"/> it always checks for changes in the included files, applies to include dynamic pages, and can take parameters; static Include pseudo-code implementation, which does not check the changes contained in the file, is suitable for containing static pages: <%@ include file= "test.html"%>

4. What are the built-in objects of JSP and what are the functions?

Request: Request in the same Servlet

Response: Response in the same Servlet

Session: With Request.getsession ()

Application: With Request.getservletcontext

Out: With Response.getwriter ()

Config: The servletconfig parameter in the Init method with Servelt

Page: Represents a Servlet instance produced by this page

Exception: for error pages, except for non-snapping

5. Common directives of JSP

<%@ page language= "java" pageencoding= "Utf-8" contenttype= "Text/html;charset=utf-8"%>

<%@ include file= "test.html"%>

<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/fmt"%>

6, what is the JSP action, what is the difference

There are 6 types of actions in JSP:

Jsp:include referencing a file when the page is requested

Jsp:usebean Find or instantiate a JavaBean

Jsp:setproperty Setting properties for JavaBean

Jsjp:getproperty output the properties of a JavaBean

Jsp:forward forwarding

Jsp:plugin generates an OBJECT tag for a Java plug-in based on browser type

7. The difference between GET and POST

The Get and post methods in the form, respectively, correspond to the Get and post methods in the HTTP protocol during data transmission.

Get is used to fetch data from the server, and POST is used to upload data to the server

GET adds the data in the form as Variable=value, followed by the URL to which the action points, using the "? "Connect, and use a" & "connection between multiple variables; POST is the data in the form that is placed in the data body, and is passed to the URL to which the action is directed, in the same way that the variable and value correspond

GET is unsafe because the data is placed in the requested URL during the transfer process, and all POST operations are not visible to the user

The amount of data sent is small, mainly because of the URL length limit, post can transfer a large amount of data, so the upload file can only use POST

GET restricts the data set for form forms to be ASCII characters, while POST supports the entire ISO10646 character set

GET is the default method for form

8. Common Web containers and development tools

Most commonly used containers: Tomcat, WebLogic

Development tools: Eclipse, JBuilder, Itellij idea

9, the basic directory structure of WEB application

WebApps

Application

JSP page

Web-inf

Classes

Lib

Xml

JSP page

Meta-inf

10. What are the similarities and differences between JSP and Servlet, and what are the links between them?

JSP is the extension of servlet technology, which is essentially a simple way for servlets to emphasize the application's view expression. The JSP is compiled with a "Servlet class". The main difference between Servlets and JSPs is that the application logic of the servlet is in the Java file and is completely detached from the HTML in the presentation layer. The case for JSP is that Java and HTML can be combined into a file with a. JSP extension. JSP focuses on views, and Servlets are used primarily for control logic

11, JSP four kinds of data sharing range

PageContext are objects and properties that are related to a page. A page is represented by a compiled Servlet class (which can have any include directive, without an include action). This includes both Servlets and JSP pages that are compiled into Servlets

Request is the object and property that the code Web client sends out for one of the requests. A request may span multiple pages, involving multiple Web components (due to the relationship of the forward directive and the include action)

A Session is a representation of the objects and properties associated with a user experience for a Web client. A Web session can also be requested frequently or across multiple clients

Application is a representation of objects and properties related to the entire Web application. This is essentially a global scope that spans the entire Web application, including multiple pages, requests, and sessions

12, the understanding of MVC, what are the pros and cons of MVC, combined with struts, explains how to use in a WEB application

The Java-based Web application system adopts the MVC architecture pattern, i.e. model, view, control (Controller) separation design, which is the mainstream design direction of Web application service system at present.

MVC design Pattern: The framework pattern of applying the observer pattern

Model: A module that processes business logic, each dealing with a module (model, Operational data processing layer, and independent of the presentation layer)

View: Responsible for the page display, display model processing results to the user, the main implementation of the data to the page conversion process (view, display data through the client data type, and echo back the execution results of the model layer)

Control: Responsible for the request distribution, the form data passed to the model processing, the processing results of the data passed to the view display (Controller, view layer and model layer bridge, control the flow of data, accept the view emitted events, and redraw the view)

JSP + Servlet + JavaBean, the controller as the core, JSP is only responsible for displaying and collecting data, servlets, connection views and models, the view layer of data sent to the model layer, JavaBean, divided into business classes and data entities, business class processing business data, data entity hosting data , basically most of the projects are using this MVC implementation pattern

13. Session Tracking Technology

Cookie, URL rewrite, set form hidden fields

14. What are the effects of filters?

Verify that the customer is from a trusted network

Re-encode the data submitted by the customer

Filter out some of the customers ' words that should not appear

Verify that the user can log on

Verify that the customer's browser supports the current app

Logging system logs

15. The role of Web. xml

User-configured web app information, such as listener, filter, Servlet

16. Commonly used JSTL tags

<c:if>

<c:choose>, <c:when>, <c:otherwise>

<c:forEach>

<c:set>

17. Middleware

Middleware is an implantable, reusable, non-business-logic component of a program

Middleware is a large class of basic software, which belongs to the category of reusable software. As the name implies, middleware is in the middle of operating system software and user's application software. Middleware on the operating system, network and database, the application of the lower layer of software, the overall role is to be in their own upper layer of application software to provide a running and development environment, to help users flexible, efficient development and integration of complex application software

Middleware is a kind of independent system software or service program, the Distributed application software uses this software to share resources among different technologies, the middleware is located on the operating system of the client server, and manages computing resources and network communication.

Example:

RMI (remote Method invocation) calls remotely

Load balancing, which will be distributed across servers

Treasparent Fail-over Transparent failover

Clustering clusters, replacing mainframes with multiple small servers

Back-end-integration backend integration, how to integrate legacy systems with existing, newly developed systems

Transaction Transaction (Global transaction: Distributed transaction) (Local transaction: transaction within the same database connection)

Dynamic redeployment is dynamically redeployed to deploy a new system without stopping the original system

System Managerment Systems Management

Threading multithreaded Processing

message-oriented Middleware Message-oriented middleware (asynchronous call programming)

Lifecycle management for Component life cycle components

Resource Pooling resource Pool

Security safety

Caching Cache

18. How to output a string of some kind of encoding

String str = new String ("Testabc". GetBytes ("Iso-8859-1"), "Utf-8");

19. Is the technology or platform or framework of the EE?

The Java EE itself is a standard, a standard platform for Enterprise Distributed application development

The Java EE is also a framework, including JDBC, JNDI, RMI, JMS, EJB, JTA and other technologies

20. What is ORM

Object Relational Mapping (Object-relational Mapping) is a technique that solves the mismatch between object-oriented and relational database, and simply says that ORM uses metadata that describes the mapping between objects and databases, and the Java Objects in a program are automatically persisted to a relational database, essentially converting data from one form to another

21, Hibernate's 5 core interface

Configuration: Configure Hibernate to create a Sessionfactory object according to its startup hibernate

Sessionfactory: Initializes Hibernate, acts as a proxy for the data storage source, creates session objects, Sessionfactory is thread-safe, means that its same instance can be shared by multiple threads being applied, is a heavyweight, level two cache

Session: Responsible for saving, updating, deleting, loading and querying objects, is thread insecure, avoid multiple threads sharing a session, is lightweight, first-class cache

Query and Criteria: Executing queries for the database

22. How Hibernate Handles transactions

Hibernate transactions are actually either the underlying JDBC Transaction package or the JTA Transaction package, using JDBC Transaction by default.

23. What are the transaction processing methods in the Connection class?

Setautocommit (Boolean Autocommint): Sets whether transactions are committed automatically, default to Autocommit

Commint (): Commit Transaction

Rollback (): ROLLBACK TRANSACTION

24. The difference between the steps to access the database in JDBC, Statement and PreparedStatement

The steps for accessing a database in Java are as follows

1) Registration Drive

2) Establish a connection

3) Create Statement

4) Execute SQL statement

5) processing the result set (if the SQL statement is a query statement)

6) Close the connection

Statement, PreparedStatement Difference

1) When creating the difference:

Statement stm = Con.createstatement ();

PreparedStatement pstm = con.preparestatement (sql);

At the time of execution:

Stm.execute (SQL);

Pstm.execute ();

2) PreparedStatement Once the SQL is bound, this pstm cannot execute other SQL, that is, it can execute only one SQL command; Statement can execute multiple SQL commands.

3) for the execution of isomorphic SQL (only the parameter value is different, the other SQL structure is the same), with PreparedStatement execution efficiency is high, support precompilation, can perform batch processing task, for heterogeneous SQL statement, Statement execution efficiency is high.

4) readability and maintainability of the code (for example, an INSERT SQL statement, STM needs to write the passed parameters in SQL, Pstm provides method pass parameters, and filters out the what Suzis asking character "'", "-" in SQL).

5) PreparedStatement improve security, prevent SQL injection, but Statement can not be achieved, can only be judged and filtered.

25, Hibernate in the Java object three states, the object how to enter a state

1) temporary status (transient)

Characteristics:

is not in the Session cache

There are no object records in the database

If the Java object enters a temporary state:

When you create an object from the new statement

When the Delete () method of the session is called, when an object is deleted from the session cache

2) persistent state (persisted)

Characteristics:

In the session cache

There are object records in the database

The session will stay synchronized at a specific time

How Java objects Enter the persistence state

Save () from the staging state to the persisted state

The load () of the session, the object returned by the Get () method

The session's find () returns the object stored in the list collection

Session update (), Saveorupdate () causes the Free State to persist

3) Free State (detached)

Characteristics:

is no longer in the session cache

A free object is transformed from a persistent state, and there may be a corresponding record in the database

How Java objects from persisted state to free State

The close () method of the session

Session of the evict () method to remove an object from the cache. Improve performance and use less.

26. The advantages of JDBC versus Hibernate

Highly efficient JDBC, direct operation database is more flexible

27, Hibernate How to delay loading

When Hibernate is querying data, the data does not exist in memory, and when the program actually operates on the data, the object exists in memory, and the delay load is implemented. Improves server performance by saving server memory overhead

28. The difference between session.load () and Session.get ()

Can read records from the database based on the specified entity class and ID, and return the corresponding entity object

If no qualifying records are found, the Get method returns NULL, and the load method throws a Objectnotfundexception

29. The difference between cookie mechanism and session mechanism

The cookie mechanism uses a scheme that maintains state on the client, while the session mechanism uses a scheme that maintains state on the server side. Because the server-side persisted scenario also needs to save an identity on the client, all, the session mechanism may need to use the cookie mechanism to achieve the purpose of saving the identity

Forward 495303098, for reference study

Java Web face question 2

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.