Introduction to Java Web

Time:2021-4-15

Main concepts in Web Development
1. Static resources: unchangeable. html、js、css
2. Dynamic resource: Java Web. Output or generate static resources. (the page users see in the browser is always a static resource)
3. Java EE: a collection of thirteen technologies. JSP / servlet is one of them.
Container: (server). Support what technology server, referred to as XX container.

Heavyweight and lightweight servers: depending on the number of services supported.

Tip:
How to distinguish the technology of javase and JavaEE? 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 Tomcat 6.0, only JRE is OK)

   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 the Chinese directory or the directory with spaces)
2. Enter the Tomcat / bin directory and execute the startup.bat Start Tomcat
3. Access with browser http://localhost : 8080 /, if you see the interface, the installation is successful!

Question:
1. Flash by
2、JAVA_ Home environment variable

Solution: configure the system environment variable Java_ HOME=”C:\jdk1.6.0_ 20″

Tip:Catalina_ The home environment variable is not recommended

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

Tip:
The default port number of HTTP protocol is 80. https://www.jb51.net— > https://www.jb51.net :80

Tomcat directory structure (specified by the server manufacturer)
Tomcat:
bin:Tomcat Start and stop scripts for
Conf: store the configuration file of Tomcat. *. properties or *. XML
Lib: store the jar package that Tomcat depends on.
Logs: store Tomcat running logs.
Temp: store temporary files
Webapps: stores web applications managed by Tomcat. There are several folders in this directory, which means that Tomcat manages several applications.
Work: This is the working directory of Tomcat.

Standard directory structure of Java Web
Myapp: (APP name)
1. HTML, 1. JS and so on
a
1.html
WEB-INF: must have, and the name must be consistent. (the file resources stored in this directory cannot be accessed directly by users)
Lib: store the jar package serving this application
web.mxl : must have. The configuration file for the current application.
Classes: it has to be. Store the class that serves the current application. com.itheima.SomeClass .     classes\com\itheima\ SomeClass.class

Tip:
What’s the difference between Lib in Tomcat and jar in lib of Java Web application?
Lib in Tomcat is a Tomcat service, which is shared by all managed Java Web applications.
The Lib of Java Web application only serves itself.

Loading order of duplicate classes: loading order of class loader
Classes in my application — jar in Lib in my application — class file in Tomcat / lib — jar in Tomcat / lib — not found, classnotfoundexception

How to deploy Java Web application to Tomcat
1. Open directory deployment: directly copy the application to Tomcat.
2. Make the application a war package. Enter the application directory and execute Jar – CVF MyApp.war .
Copy the war package to Tomcat / webapps, and the container will decompress the application automatically.

The core components of Tomcat
a. Virtual directory mapping: mapping the real directory on the local disk to a virtual directory for external access
C: (itheima / heima15 / day03) information (myapp) – > / myapp
server.xml : context element. Configure an app
Method 1: (not recommended, need to restart Tomcat)
In the < host > element, add the following contents: < context path = / myapp “docbase =” C: / / itheima / heima15 / day03 / myapp “/ >
Path: virtual directory. Start with ‘/’
Docbase: real directory. (Chinese catalogue is not good)
Method 2:
Create a configuration file with XML extension in Tomcat \ [enginename] \ [host name] \ \ directory.
The file name is the name of the virtual directory. Add the following configuration to it:
<?xml version=”1.0″?>
<Context docBase=”C:\ITHEIMA\heima15\day03\MyApp”/>

Small experiment: configure default port, default application and default page
http://localhost Time —— > C: itheima / heima15 / day03 / myapp / 1.html
Default port: modify server.xml Change 8080 to 80
Default application: (all need to be restarted) create a directory named ROOT.xml Configuration file for.
<?xml version=”1.0″?>
<Context docBase=”C:\ITHEIMA\heima15\day03\MyApp”/>
Default home page: modify the web.xml , add 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
to configure server.xml Host element in
<Host name=”www.itcast.cn”  appBase=”c:\itcastapps”/>
Name: website name
Appbase: the directory where all applications of this website are stored.

Domain name resolution: you can modify the file C: windows, system32, drivers, etc. hosts in the windows system to map the domain name and IP (change back to the original after playing)

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

Certificate authority, CA; VeriSign; Thawte; authoritative digital certificate authority.
To create a self signed digital certificate:
Keytool in JDK can create the certificate.
keytool.exe -genkey -alias ppp -keyalg RSA
The generated certificate is stored in the folder of the current login user by default.

Recommended Today

Libp2p RS version 0.3.0 introduction

V0.3.0 released on 4.23, usingAsyncRead & AsyncWriteTo replace ourReadEx & WriteEx & SplitEx; SimplifiedKad/DHTImplementation logic. modify ReadEx & WriteEx & SplitEx: At first we tried to useasync-traitTo define their own IO operationsTraitFor more pure useasync/awaitTo write code. withReadExFor example, it is roughly as follows: #[async_trait] pub trait ReadEx { async fn read(&mut self, buf: &mut […]