The face question of JSP and servlet

Source: Internet
Author: User

3. Talk about the life cycle of the servletWhen the request is received, the container checks to see if the corresponding Servlet object exists, and if it does not exist, it needs to load Servetl, instantiate the servlet, and invoke the Init method to initialize. If it already exists, create the request and response objects based on the user's requests, invoke the service method of the Servlet object as parameters, and the servlet interacts with the user through this method, and the processing of the request ends after the method executes. The Servelt object continues to wait for the next request. When the application unloads, call the Destroy method to release the resource. Multiple requests share Servelt objects. 4. What are the two parameters in the two main package javax.servlet.*;javax.servlet.http.*;7,  doget methods, and Dopost methods of the  servlet API? HttpServletRequest and HttpServletResponse, the former encapsulates the information associated with the request, which encapsulates the information associated with the response. To get the request information, get from the first parameter, to respond to the user, through the second parameter. 8,   To obtain user information, how to obtain the GetParameter method and Getparametervalues method of request, the former is used to obtain the value of single-valued form elements, which is used to obtain multi-value cases, a typical check box. The former returns a string, which returns an array of strings. Returns null if the table element specified by the parameter does not exist. 9,   to give users response information, how to complete? Sets the type of response content: Response.setcontenttype ("text/html;charset=gb2312"); Gets the output stream object: PrintWriter out = response.getwriter ( ); Output information: Println method through out 10,                In the servlet, select the user response, how to implement two ways: using the RequestDispatcher and response Sendredirect method if you use Requestdispatcher:requestdispatcher RD = request,getrequestdispatcher ("Destination file"); Rd.forward (request,response) If using the Sendredirect method Response.sendredirect ("target file"); 11,           What is the difference between the two ways of      ? The forward method of RequestDispatcher is equivalent to the function of <jsp:forward>. Similar to a method call, when executed to this line of code, the forward method to execute the target file, the request and response as parameters to the next page, so that the current page (servlet or JSP) and the target page shared the request, Values can be passed through the request object. The Sendredirect method of  response is equivalent to sending a message to the client browser, which allows the browser to re-request the target file, which, from the user's point of view, is equivalent to sending two requests, each requesting a separate request and response object. You cannot pass a value between two pages via request.   From the Address bar, the previous way to display the path of the first file in the Address bar, the second way to show the path of the file. 12,                How to get the Session object in the servlet, How to obtain a cookie using the GetSession method of the request object to get the session, GetCookies get cookie 16,                 assume that the IP address of the site is 1.2.3.4, Port 8878, the name of the application Hello,servlet access mode/hello, Now to access this servlet, how to access it?      Http://1.2.3.4:8878/hello/hello17,                 talk about Servlets.The role of the filter? The      servlet is a special servlet that can filter on a specific request path, execute a filter before accessing the path, pre-process the filter, and filter to decide whether to proceed with subsequent files. A typical application is to write user-validated code in a filter and then make the filtered path into the path of the file that needs to be validated.18, talk about the role of the servlet listenerThe servlet listener listens for specific events and executes the listener's code when these events are generated. The application can be loaded, unloaded, the session initialization, destruction, the session value changes and other events to listen. ----------------------------------------------------------------------------------------------------------- --------------------- 1. What are the built-in object functions of JSP?
A: JSP has the following 9 basic built-in components (which can correspond to the 6 internal components of ASP):
Request client requests, this request will contain parameters from the Get/post request
Response Web page back to the client's response
The properties of the PageContext Web page are managed here
Session period associated with the request
What the application servlet is doing
Output used to transmit a response
Config Servlet's architectural parts
Page JSP webpage itself
Exception exceptions for error pages, not captured
2. What are the action functions of JSP?
A: JSP has the following 6 basic actions
Jsp:include: A file is introduced when the page is requested.
Jsp:usebean: Find or instantiate a JavaBean.
Jsp:setproperty: Sets the properties of the JavaBean.
Jsp:getproperty: Outputs the properties of a JavaBean.
Jsp:forward: Move the request to a new page.
Jsp:plugin: Generates an object or embed tag for a Java plug-in based on browser type
3. What is the difference between dynamic include and static include in JSP? A : Dynamic include is implemented with Jsp:include action
It always checks for changes in the included files, is suitable for containing dynamic pages, and can take parameters
Static include is implemented with the include pseudo-code, and will not check for changes in the included files, for static pages
  
4. What are the differences between the two ways of jumping? Answer: There are two kinds, namely:
The former page does not turn to the page that the include refers to, but displays the result of the page, the main page or the original. It will return after execution, equivalent to a function call. and can take parameters. The latter completely turns to the new page and will not come back. Equivalent to the go to statement. 5, JSP's built-in objects and methods. The request represents the HttpServletRequest object. It contains information about the browser request and provides several useful ways to get the cookie, header, and session data.
Response represents the HttpServletResponse object and provides several methods for setting the response to the browser (such as cookies, header information, etc.)
The Out object is an instance of Javax.jsp.JspWriter and provides several methods that you can use to echo the output to the browser.
PageContext represents a Javax.servlet.jsp.PageContext object. It is an API for easy access to a wide range of namespaces, servlet-related objects, and a way to wrap generic servlet-related functionality.
The session represents a requested Javax.servlet.http.HttpSession object. Session can store the user's status information
Applicaton represents a Javax.servle.ServletContext object. This helps to find information about the servlet engine and the servlet environment
Config represents a Javax.servlet.ServletConfig object. This object is used to access the initialization parameters of the servlet instance.
Page represents a servlet instance that is generated from this page

The face question of JSP and servlet

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.