java day37 [web concepts review, web server software: Tomcat, Servlet learning portal]

The first chapter   web related concepts Review

1. Software architecture
1. C / S: client / server
2. B / S: browser / server

2. Resource classification
1. Static resources: after all user access, the result is the same, called static resource static resources can be directly parsed by the browser.
* Such as: HTML, CSS, JavaScript
2. Dynamic resources: Each after the user access to the same resources, the result may be different. Called dynamic resource. After the dynamic resource is accessed, you need to convert a static resource, returning to the browser
* such as: servlet / jsp, php, asp ....

3. The three elements of the communication network
1. IP: an electronic device (computer) in the network a unique identifier.
2. Port: The application uniquely identifies the computer. 0 ~ 65536
3. Transfer Protocol: provides rules for data transmission
1. Basic Agreement:
1. tcp: security protocol, three-way handshake. At a slower pace
2. udp: insecure protocol. high speed

Chapter   web server software

* Servers: server software installed computer
processing request receives the user's request, responds: server software *
* Web server software: receiving a user request to process the request, make a response.
* The web server software, you can deploy web projects, allowing users to access these items through a browser
* web container

* Common java related to web server software:
* webLogic: the Oracle Corporation, a large JavaEE server, supports all the JavaEE specification, for a fee.
* WebSphere: IBM Corporation, a large JavaEE server, supports all the JavaEE specification, for a fee.
* JBOSS: JBOSS company's large JavaEE server, supports all the JavaEE specification, for a fee.
* Tomcat: Apache Fund, small and medium JavaEE server, supports only a small number of JavaEE specification servlet / jsp. Open source, free of charge.

* JavaEE: the sum of the technical specifications of the Java language used in the enterprise development, the specification provides for a total of 13 large

* Tomcat: web server software
1. Download: HTTP: //tomcat.apache.org/
2. Installation: unzip the archive to.
* Note: The installation directory is recommended not to have Chinese and spaces
3. Uninstall: Delete the directory on the line
4. Start:
* bin / startup.bat, double-click the file to run
* Access: Enter the browser: http: // localhost: 8080 Enter access to your
http: // others ip: 8080 people visited

* possible problems:
1. the black window flashed:
* reason: JAVA_HOME environment variable is not properly configured
* solution: configure JAVA_HOME environment variable

2. Start being given:
1. Violence: find the port number occupied, and find the corresponding process, kill it
* netstat -ano
2. tender: modify its port number
* conf / server.xml
* <Connector Port = " 8888 "protocol =" HTTP / 1.1 "
connectionTimeout =" 20000 "
redirectPort =" 8445 "/>
* the default port number of the general will is 80.80 tomcat port number is the default port number for http protocol.
* Benefits: accessing, do not enter the port number
5. Close:
1. Normal Close:
* bin / the shutdown.bat
* Ctrl + C
2. Forced off:
* Click start window ×
6. The configuration:
* deployment projects Method:
1. direct the project into the webapps directory.
* / Hello: access path of the project -> Virtual Directory
* Simplify deployment: the project package labeled as a war, then war pack is placed under the webapps directory.
* War package will automatically unzip

2. Configure the conf / server.xml file
to configure the <Host> tag body
<Context docBase = "D: \ the Hello" path = "/ hehe" />
* docBase: path items stored
* path: Virtual Directory

3. Create a xml file any name in the conf \ Catalina \ localhost. Written in the file
<Context docBase = "D: \ the Hello" />
* Virtual directory: Name of the xml file

* static items and dynamic items:
* directory structure
* directory structure dynamic java project:
- project root directory
- WEB-INF directory:
- the web.xml: Web items core profile
- classes directory: directory to bytecode files
- lib directory: placing dependent jar package

* The Tomcat integrated into IDEA, and create JavaEE project deployment project.

Chapter III   Servlet: server applet

* Concept: run on the server side applet
* Servlet is an interface that defines the rules for Java classes to be accessed by a browser (tomcat recognition).
* Future we customize a class, Servlet interface replication methods.

* Getting Started:
1. Create a JavaEE project
2. Define a class that implements the Servlet interface
* public class ServletDemo1 the implements Servlet
3. implement abstract methods interface
4. Configure Servlet
configuration in web.xml:
<! - Configure Servlet - ->
<the servlet>
<the servlet-name> the demo1 </ the servlet-name>
<the servlet-class> cn.itcast.web.servlet.ServletDemo1 </ the servlet-class>
</ the servlet>

<-Mapping the servlet>
<the servlet-name > the demo1 </ the servlet-name>
<URL-pattern> / the demo1 </ URL-pattern>
</ Mapping the servlet->

* The implementation of the principle:
1. When the server receives the request from the client browser parses the request URL path, the path Servlet access to resources accessed
2. Find web.xml file, if there are <url-pattern> tag corresponding body content.
3. If there is, then find the corresponding <servlet-class> full class name
4. tomcat will bytecode file loaded into memory, and its object is to create
5. calling its methods

* Servlet life cycle approach is:
1. to be created: the init method, only once
* Servlet when being created?
* By default, the first time it is accessed, Servlet is created
* can be configured to execute the Servlet create opportunity.
* Configuration in <servlet> tag
1. When the first accessed, created
* <load-on-startup> negative value
2. When the server starts creating
* <load-on-startup> value of 0 or a positive integer

* Init method of the Servlet, performed only once, indicating a Servlet there is only one object in memory, Servlet is a singleton
when multiple users simultaneously access *, there may be thread-safety issues.
* Solution: Try not to define the member variables in a Servlet. Even if you define a member variable, do not modify the value of

2. Provision of services: service execution method, perform multiple
* each time you visit Servlet, Service method is called once.
3. be destroyed: the implementation destroy method is performed only once
executed when * Servlet is destroyed. When the server is shut down, Servlet is destroyed
* Only server normally closed, will perform the destroy method.
* Destroy method before Servlet is destroyed executed, for general release resources

Servlet3.0 *:
* Benefits:
* Support for annotations configuration. You may not need a web.xml.

* Step:
1. Create JavaEE project, select Servlet version 3.0 or more, may not create the web.xml
2. definition of a class that implements Servlet interface
3. The method of replication
4. @WebServlet annotation on the class, configured
* @WebServlet ( "resource path")

@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface WebServlet {
String name() default "";//相当于<Servlet-name>

String[] value() default {};//代表urlPatterns()属性配置

String[] urlPatterns() default {};//相当于<url-pattern>

int loadOnStartup() default -1;//相当于<load-on-startup>

WebInitParam[] initParams() default {};

boolean asyncSupported() default false;

String smallIcon() default "";

String largeIcon() default "";

String description() default "";

String displayName() default "";
}

Chapter IV   IDEA and the tomcat configuration

1. IDEA will create a profile for each project individually tomcat deployment
* View the console log: Using CATALINA_BASE: "C: \ Users \ fqy \ .IntelliJIdea2018.1 \ system \ tomcat \ _itcast"

2. workspace and project deployment tomcat web project
* tomcat real visit is "tomcat deployed web project", "tomcat deployment of web project" corresponds to all of the resources under the "Workspace Project" web directory
* WEB-INF resource directory can not be accessed directly browser.
3. breakpoint debugging: Use the "bugs" Start dubug start

Guess you like

Origin www.cnblogs.com/xuweng/p/11259952.html