Install the JAVA JDK
1. Download and install
- Open the link www.oracle.com/java/techno…
- Find the JAVA version to download. I use a MAC, so I downloaded the MAC version
JAVA 17
- Download and install
2. Configure the environment
- The installation
Java
After, the position is as follows
- Path as follows
/ Library/Java/JavaVirtualMachines/JDK - 17.0.1. JDKCopy the code
- Open terminal. Open terminal
~ /
In the directory.zshrc
vim .zshrc
Copy the code
- Then configure the Java path
Export JAVA_HOME = / Library/Java/JavaVirtualMachines/JDK - 17.0.1. JDK/Contents/HomeCopy the code
- This statement is equivalent to
export PATH="$PATH:$JAVA_HOME/bin"
Copy the code
Second, install Tomcat
1, download
- Open the link tomcat.apache.org/
- Select the version you want to download on the left
- I’m gonna download it
Tomcat 10
2, configuration,
- After the decompression, I put
~ \
directory
- Open the
~ /
In the directory.zshrc
File,.zshrc
To hide the file, you can use the shortcut keycommand + shift + .
Show hidden files - Open the terminal and enter from the command line
vim .zshrc
Copy the code
- Open the
.zshrc
File after importTomcat
thebin
Folder Directory
Export CATALINA_HOMR = / Users/bowen4 / apache tomcat -- 10.0.12Copy the code
- Add CATALINA_HOMR to the environment variable
export PATH="$PATH:$CATALINA_HOMR/bin"
Copy the code
3. Start and close
- After configuring the environment, use the terminal again to enter
Tomcat
thebin
directory
CD/Users/bowen4 / apache tomcat -- 10.0.12 / binCopy the code
- To obtain the permission to execute the.sh file, run the following command
chmod +x *.sh
Copy the code
- Then start
Tomcat
./startup.sh
Copy the code
- see
Tomcat started.
Let’s call it a success
- Open your browser and type
http://localhost:8080/
, you can see the interface below
- Can be closed in terminal
Tomcat
./shutdown.sh
Copy the code
- Refresh the browser again and you can see that you cannot link to Tomcat
Iii. Install IntelliJ IDEA
- Open the link www.jetbrains.com/idea/downlo…
- According to their own computer, select the corresponding download, my computer room
Mac M1
, so download.dmg (Apple Silicon)
- Open the
IDEA
Create a project
- Select create an empty project
- Select the project creation location and enter the project name
- To create a good
Network
After that, a window will pop up automatically, each project should have a module, we add a new module
- If you close this popover by accident, you can click
File->Project Structure...
Open the
- Click on the
Net Module
After that, pop up the window below and selectJAVA
And use ofJDK
version
- Enter the module name and click
Finish
- Click OK
- And then you can see that
01_HelloWorld
Module,src
The file contains the source code we developed
- Right click on the
src
, create aJava Class
file
- I’ll call it theta
Main
- in
Main
File to write code
- Right click and select
Run 'Main.main()'
- You can see the console print
-
The above code is for fun and does not interact with the server, so we need to do something extra
-
To create a Web Application, right-click 01_HelloWorld and select Add Framework Support…
- choose
Web Application
- In the image below, it is created
Web Application
- in
Web Application
Create atext.html
File and add a picture123.jpg
- The simple process for a client to load a back-end project is as follows
- The client sends the request
- The request comes to the server port (my default port number is 8080)
- Port sends data to
Tomcat
Tomcat
Send data to the project01_HelloWorld
- Now we give the project
Web Application
Configuration toTomcat
Go, you can goTomcat
Integrated into theIntelliJ IDEA
In the
- choose
Tomcat Server
Under theLocal
- Required for the configuration
Tomcat
- Direct selection
Tomcat
The root directory of the
- Can you give
Tomcat
Pick a name
- You want to
Tomcat
When a request is received, the data is sent to01_HelloWorld
The project must be01_HelloWorld
Project add toTomcat
In the - Click on the
Deployment
, click on the+
, click on theArtifact...
That will be01_HelloWorld
Project add toTomcat
- Because there is currently only one project
01_HelloWorld
, so clickArtifact...
If there are more than one item, it will let you select the specific item to add - Modify the
Application context
, you can usehello
access01_HelloWorld
- use
Debug
Mode to run, you can debug the program by breaking points later
Debug
After running, you can see that it started successfullyTomcat
Print prompt for
- At the same time, the browser will automatically open, the default fill
http://localhost:8080/hello/
http://localhost
Default is native8080
Is this machineTomcat
Corresponding port numberhello
is01_HelloWorld
Project, is the above modificationApplication context
- Access projects directly, such as the one here
hello
Is loaded by defaultHello
The projectWeb Application
In theindex.htm
,index.html
,index.jsp
Wait for the file, so there will be above the content display
- Of course we can modify the browser load
URL
To accessHello
In thetest.html
file
- Can also access
Hello
In the123.jpg
The picture
- create
file
Folder and willtest.html
File move tofile
folder - create
image
Folder and will123.jpg
Image move toimage
folder
- Click Debug deployment again and you will see a pop-up window, which is selected by default
Restart server
Restart server
: Restart the server and deploy itRedeploy
: The server has been started and redeployed
- We can change the popover default options by changing the position shown below
- will
Restart server
Need toRedeploy
- Click again on the
Debug
, the popover is selected by defaultRedeploy
- After redeployment, the browser was refreshed and the images could not be loaded
- You need to access a new path
http://localhost:8080/hello/image/123.jpg
Loading pictures
Four, sending network
1, write interface, send network
- in
file
Create in folderlogin.html
File and write the code below
- Open the page in the browser
- The input
The user name
andpassword
- Click on the
The login
, you can see that willThe user name
andpassword
Sent to thebaidu
2, import,Tomcat
In the library
- Because the server is the local machine, so
form
In the tagaction
Specify as follows
- Need to quote
Tomcat
The two librariesjsp-api.jar
andservlet-api.jar
- Open the window below and select
Dependencies
To addLibrary...
- Select the one previously configured
Tomcat
- Check selected
Tomcat
, click on theOK
- At this point you can see the imported exterior in the project
Tomcat
library
3. Send requests to the local server
- in
src
Create in folderJava Class
The type ofLoginServlet
File, package name according to their own ideas
- By default, enter it in a browser
http://127.0.0.1:8080/hello
, will visit the project01_HelloWorld
In theweb
Under folderindex.jsp
file
- At this point I added
@WebServlet("/login")
After, can passhttp://127.0.0.1:8080/hello/login
accessLoginServlet
Methods in a class
- in
LoginServlet
Class to adddoGet
anddoPost
Method and add a print statement to the method implementation
- will
login.html
In the fileform
Of the labelaction
Modified to/hello/login
, you can accesslogin
Method, method type used inget
Request, redeployWeb Application
- Enter in the web page
The user name
andpassword
, click on theThe login
- You can see a blank page, which indicates that the request was successfully sent, and the parameters are passed in the form of concatenation after the domain name
- Can be found in
IntelliJ IDEA
See print indoGet
- Change the method type to
post
, redeploy
- Refresh the web page and enter
The user name
andpassword
, click on theThe login
- If the page goes blank, the request is successfully sent and no parameter is concatenated after the domain name
- through
check
, you can see that the parameter passesData
Formal transfer of
- At this point, you can see the print
doPost
4. Respond to the request
- in
LoginServlet
File, add response code, redeploy
- The input
User name: 123
andPassword: 456
- Click on the
The login
To showLogin Success!
- Go back to the input screen, enter
User name: 123
andPassword: 4567
- Click on the
The login
To showLogin Failure!
4. Install Packet Tracer
1. Register the installation
- Open the link: www.netacad.com/zh-hans/cou…
- Scroll down and find
Self-paced learning online
, click on theFor details
- On the registration screen, select
countries
andDate of birth
- Fill in the
Registered Email address
.The name
.state
.Answer the questions
.Select mandatory items
- As shown below, emails have been sent to the registered mailbox
- Open the email you receive and click
Quick start
- Enter the password
- When you click
Create my account
Then, come to the following interface, this time the account has been registered
- Slide to the bottom of the screen and click
PACKET TRACER
- Find the version you need to download
- Install and Log in
Cisco Packet Tracer
After, you can operate the following interface