JSP & amp; Servlet interview questions

Source: Internet
Author: User

JSP & Servlet interview questions

The following is an interview on JSP & Servlet. We are willing to have some conflicts with the previous interview summary. However, it does not affect our learning. Therefore, we can continue to explore Jsp interview questions!

1And what built-in objects does jsp have?
A: JSP has the following nine basic built-in components (which can correspond to the six internal components of ASP ):
Request client request, which contains parameters from the GET/POST request
Response returned from the response webpage to the client
The pageContext page is managed here.
Session-related session Period
Content being executed by application servlet
Out is used to send response output.
Configuration servlet framework
Page JSP page itself
Exception for the error webpage, exceptions not captured

2. What are the functions of jsp?
A: JSP has the following 6 basic actions:
Jsp: include: Introduce a file when the page is requested.
Jsp: useBean: Find or instantiate a JavaBean.
Jsp: setProperty: Set attributes of JavaBean.
Jsp: getProperty: outputs the attributes of a JavaBean.
Jsp: forward: Transfers requests to a new page.
Jsp: plugin: generate the OBJECT or EMBED tag for the Java Plug-in based on the browser type
3. What is the difference between dynamic INCLUDE and static INCLUDE in JSP? Answer: Implement Dynamic INCLUDE with jsp: include action
It always checks changes in the contained files and is suitable for containing dynamic pages and can contain parameters
Static INCLUDE is implemented by using the include pseudo code and will not check the changes in the contained files. It is applicable to INCLUDE static pages.

4. Two jump methods. The include page only displays the results of the page. The home page is still the original page. It will return after execution, which is equivalent to a function call. In addition, parameters can be included. The latter is completely redirected to the new page and will not be returned. It is equivalent to the go to statement.5. built-in JSP objects and methods. Request indicates the HttpServletRequest object. It contains information about browser requests and provides several useful methods for obtaining cookie, header, and session data.
Response indicates the HttpServletResponse object, and provides several methods (such as cookies and header information) for setting the response to the browser)
The out object is an instance of javax. jsp. JspWriter. It provides several methods for sending output results to the browser.
PageContext indicates a javax. servlet. jsp. PageContext object. It is used to facilitate access to various namespaces and servlet-Related Object APIs, and encapsulates common servlet-related functions.
Session indicates the javax. servlet. http. HttpSession object of a request. Session can store user status information
Applicaton indicates a javax. servle. ServletContext object. This helps you find information about the servlet engine and servlet environment.
Config indicates a javax. servlet. ServletConfig object. This object is used to access the initialization parameters of the servlet instance.
Page indicates a servlet instance generated from the page.

6. Common JSP commands IsErrorPage (whether the Exception object can be used), isELIgnored (whether to ignore the expression)
7. Under what conditions do I call doGet () and doPost ()?
The method attribute in the form label in the Jsp page is doGet () when get is called, and doPost () is called when post is called ().
8. servlet Lifecycle
The web container loads the servlet and starts its lifecycle. Call the servlet init () method to initialize the servlet. You can call the service () method to call different do *** () methods based on different requests. End the service. The web Container calls the servlet's destroy () method.
9. How to Implement servlet single-thread mode 10. How to transfer objects between pages Request, session, application, cookie, etc.
11. What are the similarities and differences between JSP and Servlet, and what are their relationships?
It is an extension of Servlet technology, essentially a simple Servlet method, with more emphasis on the external expression of the application. After JSP compilation, It is a class servlet. 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.
12. Four session tracking technologies
Description of the session scope ServletsJSP page
Page No indicates the objects and attributes related to a page. A page is represented by a compiled Java servlet class (which can contain any include command but has no include action. This includes both servlet and JSP pages compiled into servlet.
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)
A session is an object and attribute associated with a user experience for a Web Client. A Web session can also frequently span requests from multiple clients.
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

13. Main Methods of the Request object:
SetAttribute (String name, Object): Set the request parameter value with name
GetAttribute (String name): returns the property value specified by name.
GetAttributeNames (): returns the name set of all attributes of the request object. The result is an enumerated instance.
GetCookies (): return all Cookie objects on the client. The result is a Cookie array.
GetCharacterEncoding (): returns the character encoding method in the request.
GetContentLength (): returns the length of the Request Body.
GetHeader (String name): Get the file header defined by HTTP
GetHeaders (String name): returns all the values of the request Header with the specified name. The result is an enumerated instance.
GetHeaderNames (): returns the name of the request Header. The result is an enumerated instance.
GetInputStream (): returns the input stream of the request to obtain data in the request.
GetMethod (): method for obtaining data transmitted from the client to the server
GetParameter (String name): Get the parameter value specified by name sent from the client to the server.
GetParameterNames (): obtains the names of all parameters sent from the client to the server. The result is an enumerated instance.
GetParameterValues (String name): obtains all values of the parameter specified by name.
GetProtocol (): gets the protocol name on which the client transmits data to the server.
GetQueryString (): Get the query string
GetRequestURI (): obtains the client address of the request string.
GetRemoteAddr (): obtains the IP address of the client.
GetRemoteHost (): Get the client name
GetSession ([Boolean create]): returns the Session associated with the request.
GetServerName (): Get the server name
GetServletPath (): Get the path of the script file requested by the client
GetServerPort (): Get the server port number
RemoveAttribute (String name): deletes an attribute in a request.

14. Which of the following methods are generally implemented during Servlet execution?
Public void init (ServletConfig config)
Public ServletConfig getServletConfig ()
Public String getServletInfo ()
Public void service (ServletRequest request, ServletResponse response)
Public void destroy ()

 

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.