Java Web Project Defense Answer question summary

Source: Internet
Author: User
Tags try catch

The total of each respondent is divided into 1.5 points. Each person asks 3 questions mainly.

development process = = = "System Architecture = = =" Project Module + function = = = "Project Gain and loss
Redirect and forward:?
Nine implicit objects?
Get and post area:?
JSP has a static inclusion, dynamic inclusion, the two areas of discrimination:?
What is MVC:?
Web system architecture:?

Java Web Project Defense

1 HTTP protocol full name and features ------------------------------------------------------

HTTP is a Hypertext Transfer Protocol (hypertext Transfer Protocol)and is a stateless protocol; HTTP follows the request/response model.

1. Support client/server mode .

2. Simple and fast : When a customer requests a service from the server, it simply transmits the request method and path. The request method commonly has, POST. Each method specifies a different type of contact between the customer and the server. Because the HTTP protocol is simple, the HTTP server's program size is small, so the communication speed is fast.

3. Flexibility: HTTP allows any type of data object to be transmitted. The type being transmitted is marked by Content-type.

4. No connection : The meaning of no connection is to limit the processing of only one request per connection. When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. In this way, the transmission time can be saved.

5. No Status: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing. A lack of state means that if the previous information is required for subsequent processing, it must be re-routed, which may cause the amount of data to be transferred per connection to increase. On the other hand, it responds faster when the server does not need the previous information.

2 Request information and response information includes-----------------------------------------------------------

Request: Request line request header empty line message body

Response: Status line response header empty line message body
3 Tomcat directory structure--content information -------------------------------------------------------------

Bin: Start and shut down the server's script file
LIB: Jar files that the server and all applications can share
Conf: Storing configuration Files
WebApps: Application Deployment Directory
Logs: Log file
Work: The directory where the servlet generated by the JSP resides

4 The life cycle of the servlet-------------------------------------------------

Servle life cycle can be broadly divided into: initialization, service, destruction of 3 stages.

initialization: The first stage primarily works, the container loads and instantiates the servlet, and triggers the init () method to load the resource.

Service Phase : mainly handles various requests and responses from the client, triggers the service () method when the request arrives, and processes the request to generate a response. The servlet is multithreaded, the container loads only one servlet instance, and the initialization executes only once, but when the request is reached, each request is processed concurrently by the thread executing the servlet's service () method.

destroy: The servlet's destruction means that the servlet instance is discarded by the container, usually when the container is closed or the container needs free memory, and the container is destroyed by calling destroy ().


5 The difference between Doget and Dopost--
6 principle of redirect forwarding -------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------

Request Forwarding:

You can only forward requests to components in the same web app, and the components that request forwarding share the same request and response objects as the components that belong to the same access request and response process.

The request is forwarded internally by the server and the response is returned.

Therefore, the browser address during the forwarding process will not jump path , is still the previous URL, because the forwarding request is the work of the server to complete . High Security .

Redirect:

You can redirect requests to other resources in the current application, to resources in other applications at the same site, or to resources that are redirected to other sites by using absolute URLs.

The requester and the requester use their own request object and the response object, which belong to two separate access request and response procedures .

The browser initiates 2 different requests , so the URL displayed in the browser's address bar changes when the redirected access process ends, changing from the initial URL address to the destination URL of the redirect.


7 How the session works--------------------------------------------------------------------------------------------------- ----------------

The principle of the session object is that the server can create and maintain a session object for the client to hold the data.

While creating the Session object, the server will generate a unique number for the session object, which is called SessionID, and the server stores the SessionID on the client in a cookie manner. The session object is saved on the server side , and the browser closes does not mean that the session object is deleted.


8 The difference between JSP and servlet----------------------------------------------------------------------------------------------------------- -----

Explanation 1: JSP is the extension of servlet technology, which is essentially a simple way of servlet. The JSP is compiled with a "class servlet". 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. JSPs focus on Views, and Servlets are used primarily for control logic.

Explanation 2: JSPs are essentially servlets, but they are created differently. Servlet is completely Java program code composition is good at process control and transaction processing and through the servlet to generate dynamic Web pages; JSP is made up of HTML code and JSP tags, which makes it easy to write dynamic Web pages

So the servlet is used to control the business process in practical application, and the JSP is used to generate the Dynamic Web page. In the struts framework, the JSP is in the view layer of the MVC design pattern, and the servlet is in the control layer.

9 Talk about your Ajax understanding-----------------------------------------------------------------------
AJAX = Asynchronous JavaScript and XML ( asynchronous JavaScript and XML).
AJAX is not a new programming language, but a new method of using existing standards.
AJAX is the art of exchanging data with a server and updating parts of a Web page without reloading the entire page.


The creation and destruction of response and request object--(time)------------------------------------------------------------------------------ --------

The Web server receives an HTTP request from the client, creating a Request object for each request, and a response object representing the response, respectively.

11 How to deploy a servlet (config)----------------------------------------------------------

Registering a servlet

<servlet>
<servlet-name>InitUser</servlet-name>---Declaring a unique name in the Web application
<servlet-class>com.cy.servlet.InitUser</servlet-class>----The full Java class location

(Initializes a parameter to a single servlet

<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
</init-param>

)

</servlet>

Mapping servlet
<servlet-mapping>
<servlet-name>InitUser</servlet-name>
<url-pattern>/InitUser</url-pattern>
</servlet-mapping>


12 often encounter error status codes and explain the meaning (explanation)--------------------------------

302: The customer requested the document elsewhere, the new URL is given in the location header, and the browser should automatically access the new URL

404: Unable to find the resource at the specified location.

500: The server encountered unexpected situation, unable to complete the customer request.

13 How data is forwarded from the servlet to the JSP to display the data -----------------------------

1 scripts

2 El expression

3 JavaBean


14 exception handling execution order try Catch finally-----------------------

If the corresponding exception is caught in try{}, interrupts the execution of the current code, executes the contents of the catch{}, and finally executes the method in finally{}, in general, the method in finally will be executed, in which the finally is used to a large extent for the release of resources.

Will the code in finally always execute?

If a method is already return before executing the try{} statement, then the finally statement specifies that it will not execute. Because it doesn't go into a try statement if you call System.exit (0) in a try statement, and then you exit the current Java Virtual machine, finally there is no chance of execution.

The HttpServletRequest object gets the request parameter method:---------------------------------

GetParameter (parametername) returns a String object.

Getparametervalues (parametername) returns a string array object.

Getparameternames () returns the list of all form parameter names in the request in the form of a enumeration (enumeration).

There are several ways to map the path of the servlet-<url-pattern>...<url-pattern>

exact pattern matching. This type of pattern is used to map requests one-to-one to the specified servlet.

The extension matches "*. Extension". in this case, all URLs ending with the specified extension are directed to the specified servlet.

path Mapping. the path map must start with '/' and End With '/* ', where any character can appear. Path matching is typically used to turn all requests for a directory to a specified servlet.

the default servlet, '/'. The default servlet mappings are used to define a servlet that requests a turn when no path information is given.


17 How to initialize parameters when configuring a servlet --------------------------------------------------

Initialize Web application parameters (<contes-param> must appear before any servlet tags)

<contes-param>

<param-name>charset</param-name>

<param-value>utf-8</param-value>

</contes-param>

Initialize parameters to a single servlet

<init-param>
<param-name>name</param-name>
<param-value>value</param-value>
</init-param>


Response object output text, binary data

Getwrite (): Text

Getoutputstream (): text, but usually sends non-textual binary information

19 questions about the session
The use of ServletConfig and ServletContext objects

ServletConfig: Initializing Parameters

ServletContext: The context object is created only once
The difference between a cookie and a session: Create a function save location

Create: Creates a cookie and sends him to the browser, by default it is a session-level cookie: stored in the browser's memory and deleted after the user exits the browser.

A server-side program, such as a servlet, is created when a statement such as Httpservletrequest.getsession (true) is called.

Role:

Save location: The cookie data is stored on the client's browser and the session data is placed on the server.
22 Submit a form when uploading a file by submitting the method:

Enctype= "Multipart/form-data" post

The effect of the request and response object:

Storage location of the jar package:

Web-inf/lib
the difference between the Get mode and the Post mode submission: ----------------------------------------------------------------------------------------------------------- -----------------------------------------

Commit data type: Get General commit text, post submit text, binary text.

Commit data length: Get has a certain length, post is not limited.

Commit data visibility: Get is displayed in the browser's address bar as part of the URL address, and post is not visible as the requested message body .

Commit data cache: The get cache is in the browser URL history state; Post is not cached by the browser.

Overall: Post security is higher than get security.


26 The difference between forwarding and redirection:

ServletContext Object Effect:

SetAttribute binding parameters and getting parameters GetAttribute
28 REDIRECT process: Corresponding status code (302)

The client browser sends an HTTP request----The Web server accepts a 302 status code response and corresponds to a new location to the client's browser-the client browser finds a 302 response, then automatically sends a new HTTP request. The request URL is the new location address----The server looks for resources and sends them to customers based on this request. Here the location can be redirected to any URL, since the browser has re-issued the request, there is no concept of request delivery. The client browser path bar displays its redirected path, and the customer can observe the change of address. The redirect behavior is that the browser has made at least two access requests.

29 What is called URL rewriting:

URL rewriting is the process of first getting a URL request to enter and then rewriting it to another URL that the site can handle.
JSP action, include ForWord directive: taglib include Page

<jsp:include> action: is a dynamic inclusion that displays the displayed results in the current page. Its syntax format is: <jsp:include page= "Localurl" flush= "true" > page represents a relative path; Flush is true to automatically empty when the buffer fills up.

<jsp:forward> action: A request sent from a client, forwarded from one JSP page to another JSP page. Its syntax format is: <jsp:forward page= "Relativeurl"/>

Page directive provides processing instructions for the current page

The include directive is used to include another file in the JSP

Taglib instructions how to include and access a custom tag library


JSP Import Tag Library:

Two jar files are required. The first file is Jstl.jar, which provides an API class for the JSTL tag library. The second file is Standard.jar, which provides the implementation class for the tag library. Copy to the Lib subdirectory under the Web-inf directory

Introduced into the JSP by <%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>. Core Standard Tag Library
Specifications of JavaBean:

The JavaBean class must be a public class and have its Access property set to publicly.

The JavaBean class must have an empty constructor.

A JavaBean class should not have public instance variables, and class variables are private. To access these class variables, you should access them through a set of access methods (GETXXX and Setxxx), and you cannot start naming member variables in uppercase letters.

JavaBean should be serializable (serializable), that is, implementing the Java.io.Serializable interface


The JSP directive: taglib include Page

Page directive provides processing instructions for the current page

The include directive is used to include another file in the JSP

Taglib instructions how to include and access a custom tag library


34 Implicit objects:

Out session page Request Response Config PageContext application exception
The JSP iterates through the data:

<c:foreach>

<c:forTokens> tags are used to loop through the members separated by delimiters in a string

The servlet life cycle, initializing

Servle life cycle can be broadly divided into: initialization, service, destruction of 3 stages.

initialization: The first stage primarily works, the container loads and instantiates the servlet, and triggers the init () method to load the resource.


PNS Web application state management solutions :

1 form hidden fields

2 cookies

3 URL Rewriting

4 Session Track


The session request period:

39 Common listeners:

Context Listener

Session Listener

Request Listener

Httpsessionbindinglistener is the only listener that does not need to be registered in Web. xml
40 Configuring the Filter:

<filter>
<filter-name>Filter1</filter-name>
<filter-class>com.cy.Filter1</filter-class>
</filter>
<filter-mapping>
<filter-name>Filter1</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>


The operation phase of the JSP:

Translation compiler class load class instantiation Initialize service destroy
42 static dynamic containing data:

The include directive is used to statically include an exception file in a JSP. Syntax: <%@ include file = "url"%>, feature: Share request domain, first include recompile, do not check for changes in included pages.

<jsp:include> dynamic Inclusion, Syntax: <jsp:include page= "url" flush= "true" > Feature: Do not share the request domain, compile and then include, will check the inclusion of the page changes.
The order in which to take the value of the El expression:

Scope Order page Request session Application
XMLHttpRequest Properties and methods:

Property:

ResponseText: Response data in the form of a string

Responsexml: Obtaining response data in XML form

Method:

Open (method,url,async)

    • method: type of request; GET or POST
    • URL: The location of the file on the server
    • Async: True (asynchronous) or false (synchronous)

Open (String):

    • string: only for POST requests


45 form submission File:

Enctype= "Multipart/form-data" cannot be used in Get mode
46 Process of uploading files:-------------------------------

47 redirect forwarding:-----------------------------------
HTTP processing process:--------------------------------

The client and the Web server establish a connection---> The client sends an HTTP request---> HTTP request from the server-side receiving client, generates an HTTP response postback---> The server-side closes the connection. The client resolves the postback response and resumes the page.
49 How to implement forwarding? -----------------------------------

Request.getrequestdispatcher (URL). ForWord (REQ,RESP);
50 Why should I manage user status? --------------------------------

The Web application is stateless. Each time a page is requested from the server, a new instance of the Web page class is created. This usually means that all the information in the page and in the control is lost every time the round trip is in progress.

HTTP is a stateless connection.
Web-Necessary directory structure:----------------------------------------------------

Configuration file (Web. xml); static files and JSP classes; files and packages
52 Filter Filter Four types: ForWord include request error--------------------------------------------------

The filter corresponds to the request method, can be requested, INCLUDE, FORWARD, error four one, the default is request

Java Web Project Defense Answer question summary

Related Article

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.