Java face question (ii)

Source: Internet
Author: User
Tags imap php language microsoft iis

One , say the servlet's life cycle, and tell the difference between a servlet and a CGI?

When the servlet is instantiated by the server, the container runs its Init method, the service method is run when the request arrives, and the service method automatically dispatches the Doxxx method (Doget,dopost) corresponding to the request, etc. The Destroy method is called when the server decides to destroy the instance.

The difference from CGI is that the servlet is in a server process, it runs its service method in a multithreaded manner, one instance can serve multiple requests, and its instances are generally not destroyed, and CGI generates a new process for each request, which is destroyed after the service is completed. So the efficiency is lower than the servlet.

A , forwarding (forward) and redirection (redirect)?

Forward (forwarding): Is the server requests the resource, the server directly accesses the URL of the destination address, reads the response content of that URL, and then sends the content to the browser. The browser does not know where the server sent the content from, because the jump process is actually implemented by the server, is not implemented in the client, so the client does not know the jump action, so its address bar is still the original address.

Redirect (redirect): Is the server based on logic, send a status code, tell the browser to re-request that address. So the address bar shows a new URL.

Forwarding is the server behavior, and redirection is the client behavior.

- , what are the built-in objects for JSP? What are the roles?

SP total of 9 basic built-in Components

1, Request object client requests, this request will contain the parameters from the Get/post request through it to understand the customer's needs, and then respond.

2. The response object responds to customer requests for information

3, Session object it refers to a client-server session, starting from the client connection to a webapplication of the server until the client disconnects from the server.

4. Out object It is an instance of the JspWriter class and is an object commonly used to output content to the client

5, Page object It is to point to the current JSP page itself, a bit like the this pointer in the class, it is an instance of the Java.lang.Object class

6. Application object It realizes the sharing of data among users, and can store global variables. It starts at the start of the server until the server shuts down

7. Exception object It is an exception object, which is generated when a page has an exception during the run.

8. PageContext object It provides access to all objects and namespaces within the JSP page

9. config object it is the JSP engine that passes information to it when a servlet is initialized.

- , get and post requests differ?

1.GET request, the requested data is appended to the URL, to split the URL and transfer data, multiple parameters with & connection. The encoding format of the URL is encoded in ASCII rather than Uniclde, meaning that all non-ASCII characters are encoded before being transmitted.

POST request: The POST request places the requested data in the package body of the HTTP request packet. The item=bandsaw above is the actual transfer data.

2, the size of the transmitted data

In the HTTP specification, there is no limit to the length of the URL and the size of the data being transmitted. However, in the actual development process, for get, the specific browser and server to the length of the URL is limited. Therefore, when you use a GET request, the transfer data is limited by the URL length.

In the case of post, it is theoretically not restricted because it is not a URL, but in fact each server specifies that the size of the post submission data is limited, and that Apache and IIS have their own configuration.

3. Security

The security of post is higher than get. The security here refers to real security, and unlike the security methods mentioned above, the security mentioned above is simply not modifying the server's data. For example, in the login operation, through the GET request, the user name and password will be exposed to the URL, because the login page is likely to be cached by the browser and other people to view the history of the browser, the user name and password is easy to get someone else. In addition, the data submitted by get requests may also cause Cross-site request Frogery attacks, so the data for the GET request is exposed in the address bar, and the POST request does not.

the , common web container

Tomcat

Type: servlet container and HTTP Web server

Features: Implements some of the features of the Java Servlet, JSP pages, Java El and WebSocket, and pure Java HTTP Web server.

Important Components:

Catalina is a servlet container

Coyote is a connector

Jasper is the Tomcat JSP engine, and parsing the compiled JSP is called a servlet, and at runtime, you can detect changes to the JSP and recompile them.

Cluster is used to manage large applications to make LB

Was (Wephere application Server)

Web application server, a software product that plays the role of Web application server, is a software framework and middleware for Java-based Web application services.

Was can be used with many Web server configurations, including Apache HTTP servers, Netscape Enterprise Servers. Microsoft IIS Server, IBM HTTP server.

JBoss Web server integrates the Apache HTTP Server,servlet engine, LB and Tomcat local libraries

Jetty Web Server

Java-Developed Web server

Type: Web server and Servlet container

Free Open Source

For Apache activemq/alfresco/apache geronimo/apache maven/apache spark/google App engine/eclipse/fuse/idempiere/ Twitter ' s streaming api/zimbra.

Oracle WebLogic Server

is a Java EE application server, which is now maintained by Oracle and is developed by WebLogic.

Apache HTTP Server

Apache Software Foundation Development

C and XML development

Type: Web server

Apache is the most widely used Web server.

Support perl/python/tcl/php language, SSL, TLS, proxy, url rewriting, log filtering, etc.

Apache supports many plug-in module extensions,

Support for virtual hosting allows one Apache to deploy multiple Web sites while supporting 1W connections

Reverse proxy (with cache): LB (with activity check), multiple load balancing mechanisms, fault tolerance (failback)/WEBSOCKET/FASTCGI/SCGI/AJP and Uwsgit support (with cache), dynamic configuration

Nginx

Web server, reverse proxy, mail forward proxy.

The reverse proxy server supports TCP, UDP, HTTP, HTTPS, SMTP, POP3, and IMAP protocols, as well as load balancing and HTTP caching capabilities.

Nginx uses synchronous event-driven methods to process requests.

HTTP proxy and Web server features

The 1W sync connection is processed with 2.5MB memory, and the synchronization connection is maintained.

Working with static files, index files, and automatic index files

Reverse Proxy with cache

Load balancing with health checks.

Fault tolerant

Tls/ssl

WebSocket and HTTP1.1

FLV and MP4 streams

Web page access authentication

gzip Compression and decompression

URL rewriting

Request Processing Idle

Embed Perl scripts

Mailbox Agent Features

TLS, SSL support

STARTTLS Support

SMTP, POP3, and IMAP proxies

External HTTP Server Authentication

Haproxy

C language Development, free, open source, provide high availability load balancer and tcp/http agent.

Performance: Servers with dual-core Opteron or Xeon processors typically reach between 15000 and 40000 hits per second and have trouble saturating Linux under 2 gbit/sec connections.

IHS (IBM Http Server)

is a Web server, implemented based on the Apache server, that supports IBM's was application server integration. Used to do load balancing.

- , what is the relationship between JSP and servlet?

1.jsp is compiled into a servlet. (The essence of JSP is that SERVLET,JVM can only recognize Java classes, not the code of the JSP, the Web container compiles the JSP code into the Java class that the JVM can recognize)

2.jsp is better at displaying pages, and Servlets are better at logic control.

There are no built-in objects in 3.Servlet, the built-in objects in the JSP must be obtained by HttpServletRequest objects, HttpServletResponse objects, and HttpServlet objects.

JSP is a simplification of servlets, the use of JSP only need to complete the programmer needs to output to the client's content, JSP java script How to mosaic into a class, by the JSP container to complete. The servlet is a complete Java class, and the service method of this class is used to generate a response to the client.

- , four scopes in the JSP?

Page: The current pages, that is, as long as the jump to another page is invalid

Request: one session, simple comprehension is valid within a single request

Session: Browser process, as long as the current page is not closed (not forced to clear by the program), regardless of how the jump is valid

Application: Server, data is valid as long as the server is not restarted (not enforced by the program)

- , how to implement single-threaded mode for JSP or servlet?

The JSP command that implements the single thread of the servlet is: <%@ page isthreadsafe= "false"%>

<%@ page isthreadsafe= "True|false"%>

The default value is True

The Isthreadsafe=false mode indicates that it is running in singleton mode.

This mode implements the interface Singlethreadmode,

This mode has only one instance at a time, and there is no concept of whether or not information is synchronized.

If multiple users access a page of this mode at the same time,

After the visitor has completely executed the page, the visitor does not begin.

+ , what are the techniques for implementing session tracking?

1). Hide form fields: <input type= "hidden", ideal for session applications that require a large amount of data storage.

2). URL rewrite: The URL can be appended with parameters, and the server's request is sent together, these parameters are name/value pairs. See http://blog.csdn.net/xh16319/article/details/8464055

3). Cookie: A cookie is a small, named data element. The server uses the Set-cookie header to use it as an HTTP

Part of the response is delivered to the client, the client is requested to save the Cookie value, and the subsequent request to the same server uses a

The Cookie header returns it to the server. Compared to other technologies, one of the advantages of cookies is that after the end of a browser session, even

It can still retain its value after the client computer restarts. See: http://blog.csdn.net/xh16319/article/details/8464319

4). Session: Bind an object to a session using the SetAttribute (String str,object obj) method

- , what are the effects and usage of filters?

Filters, as the name implies, can be implemented and preprocessed by the code.

Popular point of view filter equivalent to the gas station, request is a road, response is a road, the destination is the servlet, where the gas station is located where the data operation can be controlled by you.

Note: Filters can be pre-processed before request and response, effectively filter out unwanted content, and filter can be reused, saving a lot of reuse code, improve Java code execution efficiency

Servlet filters are small WEB components that intercept requests and responses to view, extract, or somehow manipulate data that is being exchanged between the client and server. Filters are WEB components that typically encapsulate some functionality, though important, but are not conclusive for processing client requests or sending responses. Typical examples include recording data about requests and responses, handling security protocols, managing session properties, and so on. Filters provide an object-oriented, modular mechanism for encapsulating common tasks into pluggable components that are declared by a configuration file and processed dynamically.

Declarative: Filters are declared by using XML tags in the WEB deployment descriptor. This allows you to add and remove filters without having to change any application code or JSP pages.

Dynamic: The filter is called by the Servlet container at run time to intercept and process requests and responses.

Flexible: Filters are widely used in Web processing environments, covering many of the most common auxiliary tasks, such as logging and security. Filters are also flexible because they can be used to perform preprocessing and post-processing on direct calls from clients, and to handle requests that are dispatched between WEB components behind a firewall. Finally, you can link the filters to provide the necessary functionality.

Modular: By encapsulating application processing logic into a single class file, the filter defines a modular unit that can be easily added to or removed from the request/response chain.

Portable: Like many other aspects of the Java platform, Servlet filters are portable across platforms and containers, further supporting the modular and reusable nature of the Servler filter.

Reusable: Thanks to the modular design of the filter implementation class, and the declarative filter configuration, filters can be easily used across different projects and applications.

Transparent: Include filters in the request/response chain, which is designed to complement (rather than in any way replace) the core processing provided by a servlet or JSP page. As a result, filters can be added or removed as needed without breaking the servlet or JSP pages.

So a Servlet filter is a modular reusable component that is flexibly declared through a configuration file. Filters dynamically process incoming requests and outgoing responses, and can add or remove them transparently without modifying the application code. Finally, filters are independent of any platform or Servlet container, allowing them to be easily deployed to any compatible Java EE environment.

Java face question (ii)

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.