Introduction to javaweb and web

  • 2020-06-01 10:46:45
  • OfStack

Key concepts in Web development
1, static resources: 1 into the invariable. html, js, css
2. Dynamic resources: JavaWeb. Output or generate static resources. (the page the user sees with the browser is always static.)
3. JavaEE: a collection of technologies in 103. JSP/Servlet belong to one of them.
Container :(server). What technology is supported server, XX container for short.

Heavyweight and lightweight servers: how many services are supported is up to you.

Tip:
How do you differentiate between JavaSE and JavaEE technologies? java. * * * JavaSE javax. * * JavaEE


The server

1, http: / / www. apache. org
2. Tomcat6.0 Servlet/JSP:2.5/2.1 JDK:1.5(starting from Tomcat6.0, only JRE is acceptable)

Tomcat7.0 Servlet/JSP:3.0/2.2 JDK:1.6


Tomcat installation and problem solving
1. Unzip to a directory or disk (please do not unzip to a Chinese directory or a directory with Spaces)
2. Enter the Tomcat\bin directory and launch Tomcat by executing startup.bat
3, use the browser to access http://localhost:8080/, if you see the interface, it means the installation is successful!


Question:
1, 1 flashed by
2. JAVA_HOME environment variable


Solution: configure the system environment variable JAVA_HOME="C:\ jdk1.6.0 _20"


Tip:Catalina_home environment variable is not recommended for configuration


3. Port occupied: the default port used by Tomcat is 8080.
Change the default port number of Tomcat: find Tomcat\conf\ server.xml, search for 8080, change it to your own port (not used by anyone else)


Tip:
The default port number used by the HTTP protocol is 80. https: / / www. ofstack. com - > https://www.ofstack.com:80


Tomcat directory structure (specified by the server vendor)
Tomcat:
bin: start and stop scripts for Tomcat
conf: stores the configuration files of Tomcat. *. properties or *. xml
lib: stores jar packages that Tomcat relies on.
logs: store the operation log of Tomcat.
temp: store temporary files
webapps: stores Web applications managed by Tomcat. There are several folders in this directory, which represent several applications currently managed by Tomcat.
work: this is the working directory of Tomcat.

Standard directory structure of JavaWeb (specification by SUN)
MyApp :(application name)
1.html, 1.js, etc
a
1.html
WEB-INF: must have, and the name must be 1 to 1. (the file resources stored in this directory cannot be directly accessed by users)
lib: store the jar package that serves the application
web.mxl: it must be. The configuration file for the current application.
classes: it must be. Store the class class that serves the current application. com. itheima. SomeClass. classes \ com \ itheima \ SomeClass class


Tip:
What is the difference between lib in Tomcat and jar in lib in JavaWeb?
lib in Tomcat serves as Tomcat and is Shared by all managed JavaWeb applications.
JavaWeb USES lib only for itself.


The order in which classes are loaded: the order in which class loaders are loaded
classes-- in my own application > jar-- in lib in my own application > Tomcat\ class file -- in Tomcat\lib > jar-- "Tomcat\lib" not found, ClassNotFoundException

How do I deploy JavaWeb to Tomcat
1. Open directory deployment: copy directly to Tomcat.
2. Package your apps as war. Go to the application directory and execute jar-cvf MyApp.war.
Copy the war package to Tomcat\webapps and the container will automatically unpack the application.


The core components of Tomcat
a, virtual directory mapping: maps the real directory on the local disk to a virtual directory for external access
C:\ITHEIMA\heima15\day03\ data \MyApp -- > /MyApp
server. xml: Context elements. Configure 1 application
Approach 1 :(not recommended, need to restart Tomcat)
in < Host > Add the following to the element: < Context path="/MyApp" docBase="C:\ITHEIMA\heima15\day03\MyApp"/ >
path: virtual directory. Starting with "/"
docBase: real directory. (Chinese directory is not good)
Method 2:
Create a configuration file with an xml extension in the Tomcat\[enginename]\[hostname]\ directory.
This file name is the name of the virtual directory, in which the following configuration is added:
< ?xml version="1.0"? >
< Context docBase="C:\ITHEIMA\heima15\day03\MyApp"/ >

Small experiment: configure default port, default application, default page
http: / / localhost -- -- -- -- -- - > C:\ITHEIMA\heima15\day03\MyApp\1.html
Default port: modify server.xml to change 8080 to 80
Default application :(all need to be restarted) create a configuration file named ROOT.xml in the Tomcat\[enginename]\[hostname]\ directory.
< ?xml version="1.0"? >
< Context docBase="C:\ITHEIMA\heima15\day03\MyApp"/ >
Default home page: modify web.xml in the application by adding the following:
< ?xml version="1.0" encoding="ISO-8859-1"? >


< web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" >
< welcome-file-list >
< welcome-file > index.html < /welcome-file >
< welcome-file > 1.html < /welcome-file >
< welcome-file > index.jsp < /welcome-file >
< /welcome-file-list >
< /web-app >
b, virtual host
Configure the Host element in server.xml
< Host name="www.itcast.cn" appBase="c:\itcastapps"/ >
name: website name
appBase: directory for all applications on this site.

Domain name resolution: the C:\WINDOWS\ system \etc\hosts file can be modified to map the domain name and IP (change back to original after playing).

c, connector: SSL
HTTPS = HTTP + SSL. The default port used is 443.Tomcat: 8443
SSL: data encryption (asymmetric encryption) + identity authentication (digital certificate)

Certificate Authority CA; VeriSign; Thawte; Authoritative digital certificate authority.
Create a self-signed digital certificate:
keytool in JDK can create this certificate.
keytool.exe -genkey -alias ppp -keyalg RSA
The generated certificate is stored by default in the folder of the currently logged in user.


Related articles: