JSP web application development questions and answers

Source: Internet
Author: User
1. Which of the following methods are generally implemented during servlet execution?
A: Which of the following methods are generally implemented during servlet execution?
(1) Public void Init (servletconfig config)
(2) Public servletconfig getservletconfig ()
(3) Public String getservletinfo ()
(4) Public void Service (servletrequest request,
Servletresponse response)
(5) Public void destroy ()

2. Tell the servlet lifecycle and the difference between Servlet and CGI.
A: After the servlet is instantiated by the server, the container runs its init method. When the request arrives, the Service () method is run. The Service () method automatically runs the doxxx method (doget, the server decides to call the destroy () method when the instance is destroyed.
The difference with CGI is that the servlet is in a server process and runs its service () method in multiple threads. An instance can serve multiple requests, and its instance is generally not destroyed, CGI generates a new process for each request. After the service is completed, it is destroyed, so the efficiency is lower than that of servlet.

3. Differences between forward and redirect.

A: forward is the server that requests resources. The server directly accesses the URL of the target address, reads the response content of the URL, and sends the content to the browser, the browser does not know where the content sent by the server comes from, so its address bar is still the original address.

Redirect means that the server sends a status code based on logic to tell the browser to request the address again. Generally, the browser will re-request the address with all the parameters just requested, so the session and request parameters can be obtained.

4. When do I call doget () and dopost ()?
A: The method attribute in the form label in the JSP page is doget () when get is called, and dopost () When post is called ().

5. What are the similarities and differences between JSP and Servlet, and what are their relationships?
A: JSP is an extension of Servlet technology. It is essentially a simple servlet method, with more emphasis on the external expression of the application. After JSP compilation, it is "servlet-like ".
The main difference between Servlet and JSP is that the application logic of servlet is in the Java file and is completely separated from the HTML in the presentation layer. In JSP, Java and HTML can be combined into a file with the extension ". jsp. JSP focuses on views. servlet is mainly used for control logic.

6. What is the difference between dynamic include and static include in JSP?
A: Dynamic include is implemented using the JSP: include action. It always checks changes in the contained files. It is suitable for inclusion of dynamic pages and can contain parameters. Its code is:
<JSP: Include page = "embedded ded. jsp" Flush = "true"/>
Static include is implemented by using the include pseudo code. It does not check the changes in the contained files. It is applicable to static pages. The code is:
<% @ Include file = "included.htm" %>

7. What are the four session tracking technologies?
A: The description of the session scope servlets JSP page is as follows:
(1) page indicates objects and properties related to a page. A page is represented by a compiled java servlet. This includes both Servlet and JSP pages compiled into servlet.
(2) A request is an object and attribute related to a request sent by a Web Client. A request may span multiple pages and involves multiple Web Components (due to the relationship between the forward instruction and the include action ).
(3) session is an object and attribute related to a user experience for a Web Client. A web session can also frequently span requests from multiple clients.
(4) Application represents the objects and attributes related to the entire web application. This is essentially a global scope that spans the entire web application, including multiple pages, requests, and sessions.

8. What actions does JSP have? What are their roles?
A: JSP has the following six basic actions:
(1) JSP: Include indicates that a file is introduced when the page is requested.
(2) JSP: usebean indicates finding or instantiating a JavaBean.
(3) JSP: setproperty indicates setting attributes of JavaBean.
(4) JSP: getproperty indicates the attribute of a JavaBean output.
(5) JSP: Forward indicates to transfer the request to a new page.
(6) JSP: plugin indicates that the object or embed tag is generated for the Java Plug-in based on the browser type.

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.