Four Java Web Test centers

Source: Internet
Author: User

One, get and post differences (refer to servlet&jsp study notes)

The <form> method property defaults to get.

1, the use of post conditions

Get following URL, request parameter length is limited, too long request parameter or file upload this kind of big data operation, with Post.

Get request parameters appear in the Address bar, sensitive information or confidential information, with post.

Some browsers cache data according to the address bar, the address bar is the same when the direct access to the cache of old data, do not send a request to the server, the general use of post.

Post is used for non-idempotent operations (such as additions and deletions ).

2, the use of Get cases

Post request parameters do not appear in the address bar, can not be added to the browser bookmarks , I want users to follow the different request parameters can be set bookmarks, with get.

Get is used for idempotent operations, such as queries .

Note: idempotent operations refer to just acquiring data without altering the data on the server.

Second, explain what a servlet is, and talk about the life cycle and basic structure of the servlet 1, servlet concepts (refer to servlet&jsp learning notes)

A servlet is a Java class that is loaded and initialized by a Web container (such as Tomcat) and managed by a container to become a servlet. Without the container, the servlet is just a Java class and cannot respond to client requests.

The servlet runs in the container and the container has a JVM boot. Each time a request arrives, a thread is opened by the container and the servlet is determined to process the request. If multiple requests arrive, multiple threads are started instead of restarting the JVM process. So significantly reduce the performance burden.

2. servlet life cycle

The life cycle of a servlet is divided into the following phases:

(1) Load (instantiation): Loaded (instantiated) when the Web container is started or when the servlet is first accessed (default);

(2) Initialization: After instantiation, the container invokes its init () method for servlet initialization;

(3) Process request: Call its service () method when the request arrives. The service method automatically calls the Doget () or Dopost () method corresponding to the request;

(4) End: When the service ends (when the container is closed), the container calls its destroy () method.

3, the servlet class wording

Iii. the difference between forward and redirect in the Servlet API (refer to Servlet&jsp learning Note) 1, RequestDispatcher Forward () method--server-side jump

Request.getrequestdispatcher ("Some.do"). Forward (request,response);//Relative URL

Forward () forwards the request to the specified URL, and the requested forwarding is made in the container, rather than through the HTTP response notification browser for redirection (Redirect). The browser does not know that the request was forwarded, so the address bar does not change.

You can use this method if you intend to access the files in the application Web-inf.

This method is more efficient than server-side jumps and helps to hide the actual links, so use this method as much as possible. However, in some cases, if you need to jump to a resource on another server, you must use Sendredirect ().

2, HttpServletResponse Sendredirect () Method--Client jump

Response.sendredirect ("http://openhome.cc");

Sendredirect () can ask the browser to re-request another URL, also known as redirection (Redirect), which can be used to specify an absolute URL or a relative URL. This method will set the HTTP status in the Response 301 and the location header, after the browser receives this header, will re-use the Get method to request the specified URL (containing all the parameters just requested), so the address bar will change. Because the HTTP status code is used to redirect the header, this method must be executed before responding to an unconfirmed output, otherwise throwing an exception.

Iv. the similarities and differences between JSP and servlet, what is the connection between them

1. Difference

The servlet focuses on the control logic, primarily for the definition of Java program logic, and avoids directly generating page output in the servlet (such as writing HTML directly).

JSP is an extension of servlet technology, which is essentially a servlet, but JSP is a. jsp file that combines Java and HTML, focusing on the view.

2. Contact

The JSP is translated as a ". Java" source of the servlet by the Web container, compiled into a ". Class" file, and then loaded into the container, so the last service is a servlet instance.

V. What are the main methods of the Request object? The difference between Request.getattribute () and Request.getparameter () Vi. What are the built-in objects for JSP? What are the roles? What are the different methods? Vii. What are the actions of JSP? What are the roles? (non-focus) eight, JSP commonly used Directives IX, JSP dynamic inclusion, static inclusion of the difference ten, what is the difference between the two ways of jumping? Xi. method of object passing between pages 13, MVC 14, coding XV, actual combat

Four Java Web Test centers

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.