The servlet programming question in Tc608--java

Source: Internet
Author: User

  
   
    servlet collation Author:lxy1. What is a servlet? Running in a servlet container, the server server directly parses the running Java application applet, 2. How to create a servlet essence: by inheriting or implementing an interface class and overriding the method. Step: [1]. Create a class that inherits HttpServlet (either implementing the Servlet interface or inheriting the Genericservlet Class) [2]. Overriding methods, Doget, Dopost, and so on (interfaces need to override all methods, However, the service method is processing the request) [3]. In the Web. xml file, configure
    the
  
  
   
    3.Servlet life cycle: Approximate process: [1]. Create a Servlet object and invoke the Init () method to initialize the Web with resource [2]. The service method is used to process the request [3]. Destroy servlet details with destroy: [1 ]. When a servlet is created, a Servlet object is created the first time the web is accessed, and the Init method is called, and a thread is invoked to invoke the service method, and Init is called only once [2]. When a second access is opened, a thread is invoked to invoke the service method to process the request [3]. The servlet resides in memory, and is typically created only once. [4]. If you create a member variable in a servlet to handle thread safety, try to avoid creating
   
  
  
   The relationship between the 
   
     4.Servlet interface and the Doget and Dopost methods in the HttpServlet class? [1]. When a servlet is accessed, the default service method processes the request, and the [2].service method is defined in the servlet, but the specific content is httpservlet in the [3]. In the service method of HttpServlet, Different methods are called according to the request method [4]. According to polymorphism, when calling Doget, Dopost, call the method of their own servlet supplement: template design mode: Public abstract class Car {public abstract void F IRE ();    Spark public abstract void run ();//Travel public abstract void Stop ();//stop//template public void Drive () {fire (); run (); Stop ();} }//The BMW class public class that inherits the Car interface BMW extends Car {@Overridepublic void Fire () {System.out.println ("BMW Fire");} @Overridepublic void Run () {System.out.println ("BMW Run");   @Overridepublic void Stop () {System.out.println ("BMW Stop");}    }//Test public class Test {public static void main (string[] args) {Car c = new BMW (); c.drive ();} }

   
  
  
   
    5. Know the folder in Tomcat: |-bin store startup, shutdown and other server programs |-conf store configuration information |-lib store the jar package |-logs store the log files |-temp the temporary files |-webapps storage deployment applications, There are several folders on the inside there are several applications |-web-inf |-classes Java class |-lib Java class run required jar package |-web.xml WAB app profile |-images pictures and other media File |-work Server working directory
   
  
  
   
    automatic loading of 6.Servlet: [1]. By adding <load-on-startup>2</load-on-startup> to the Web. xml file <servlet> tag
Create a servlet to follow the server startup [2]. function: Load resources [3]. The value of the tag is 1--10, the values are small and the priority is high, and the precedence is loaded in the configuration order. 
   
  
  
   
    url-pattern:[1 in 7.Servlet configuration]. Can a servlet map to multiple paths?
can [2].url-pattern] a. The exact match requirement must begin with "/" B. Directory match: Start with a "/" with a * end C. Extension matches: At the end of the *.xxx three priority: a > B > C; 
   
  
  
   
     path problems in 8.web development: [1]. How many ways does the browser access the server? A. browser address bar Enter URL B. Super Practice level <a href= "http://www.itheima.com" > Dark Horse </a> c. form <form action= "...." method= "POST" &G t;...</form>//Common request mode post get, except the form can post, the others are get d.javascript[2]. Access to the servlet path A. Absolute path: The |--band protocol is typically used to access out-of-site resources, developing infrequently With <a href= "http://www.baidu.com" > Baidu </a> |--without agreement to write a "/", equivalent to the server path, followed by the project name, plus the resource name can be used to access the resources in the station, development       Common <a href= "/day7_2/demo1" >demo1Servlet</a> equivalent: http://localhost:8080 B. Relative path: |--./xxx with the path to the second directory (project name) |-- .. /xxx return to the previous level to find the target conclusion: the use of absolute path without protocol "/value of Engineering name/servlet-pattern" is recommended in development 
   
  
  
   The Init method in the 
   
     9.Servlet interface: [1]. Why is the Init method in the Servlet interface parameterized and the method we are overriding has no parameters? |--the init (servletconfig config) method is overridden in the parent class , the method we override is not a method in the interface but is defined in its parent class [2]. What is servletconfig and what does it do? The |--servletconfig object represents the configuration object of the servlet, created by the server, and each servlet has its own ServletConfig object, which is not public |--    function: public void init (ServletConfig config) throws servletexception {this.config = Config;this.init ();} |---Get initialization parameters when a servlet is first accessed, a ServletConfig object is created and passed to the servlet through the Init method, so we can get its configuration information in the Servlet |---    You can get the name of the servlet to get the ServletConfig object: This.getservletconfig ();   |---can get the common API for ServletContext object servletconfig: |--public String getservletname (); Used to get the servlet name |--public string getinitparameter (string name); Used to get the value specified in Init-parent |--public enumeration Getinitparameter (String name);  Used to get all the name names in the Init-param |--public Servlet servletcontext getservletcontext (); Used to get a ServletContext object 
   
  
  
   
    10. About ServletContext objects [1]. ServletContext represents a Web application [2]. Gets the ServletContext object servletconfig. Getservletconfig (); [3]. function: A. Get global initialization parameters string Getinitparameter (string name) enumeration Getinitparameternames () You can configure global initialization parameters in the Web. xml file <context-param><param-name>name</param-name>vparam-value>tom</param-value></ Context-param> This configuration is for the entire web App B. Let the servlet implement information sharing ServletContext is a domain object (equivalent to a map, which is used throughout the Web application) C. Can get Path (Resource) *-* in W In EB Development, an absolute disk path must be used to obtain resources. Example Summary: 1.web does not access files other than MyEclipse Webroot, deployment only content in this file will be deployed into the server
   
    

The servlet programming question in Tc608--java

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.