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 versionJAVA 17

  • Download and install

2. Configure the environment

  • The installationJavaAfter, 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 itTomcat 10

2, configuration,

  • After the decompression, I put~ \directory

  • Open the~ /In the directory.zshrcFile,.zshrcTo 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.zshrcFile after importTomcatthebinFolder 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 enterTomcatthebindirectory
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 startTomcat
./startup.sh
Copy the code
  • seeTomcat started.Let’s call it a success

  • Open your browser and typehttp://localhost:8080/, you can see the interface below

  • Can be closed in terminalTomcat
./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 roomMac M1, so download.dmg (Apple Silicon)

  • Open theIDEACreate a project

  • Select create an empty project

  • Select the project creation location and enter the project name

  • To create a goodNetworkAfter 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 clickFile->Project Structure...Open the

  • Click on theNet ModuleAfter that, pop up the window below and selectJAVAAnd use ofJDKversion

  • Enter the module name and clickFinish

  • Click OK

  • And then you can see that01_HelloWorldModule,srcThe file contains the source code we developed

  • Right click on thesrc, create aJava Classfile

  • I’ll call it thetaMain

  • inMainFile to write code

  • Right click and selectRun '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…

  • chooseWeb Application

  • In the image below, it is createdWeb Application

  • inWeb ApplicationCreate atext.htmlFile 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 toTomcat
    • TomcatSend data to the project01_HelloWorld

  • Now we give the projectWeb ApplicationConfiguration toTomcatGo, you can goTomcatIntegrated into theIntelliJ IDEAIn the

  • chooseTomcat ServerUnder theLocal

  • Required for the configurationTomcat

  • Direct selectionTomcatThe root directory of the

  • Can you giveTomcatPick a name

  • You want toTomcatWhen a request is received, the data is sent to01_HelloWorldThe project must be01_HelloWorldProject add toTomcatIn the
  • Click on theDeployment, click on the+, click on theArtifact...That will be01_HelloWorldProject add toTomcat

  • Because there is currently only one project01_HelloWorld, so clickArtifact...If there are more than one item, it will let you select the specific item to add
  • Modify theApplication context, you can usehelloaccess01_HelloWorld

  • useDebugMode to run, you can debug the program by breaking points later

  • DebugAfter running, you can see that it started successfullyTomcatPrint prompt for

  • At the same time, the browser will automatically open, the default fillhttp://localhost:8080/hello/
    • http://localhostDefault is native
    • 8080Is this machineTomcatCorresponding port number
    • hellois01_HelloWorldProject, is the above modificationApplication context

  • Access projects directly, such as the one herehelloIs loaded by defaultHelloThe projectWeb ApplicationIn theindex.htm,index.html,index.jspWait for the file, so there will be above the content display

  • Of course we can modify the browser loadURLTo accessHelloIn thetest.htmlfile

  • Can also accessHelloIn the123.jpgThe picture

  • createfileFolder and willtest.htmlFile move tofilefolder
  • createimageFolder and will123.jpgImage move toimagefolder

  • Click Debug deployment again and you will see a pop-up window, which is selected by defaultRestart server
    • Restart server: Restart the server and deploy it
    • Redeploy: The server has been started and redeployed

  • We can change the popover default options by changing the position shown below

  • willRestart serverNeed toRedeploy

  • Click again on theDebug, 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 pathhttp://localhost:8080/hello/image/123.jpgLoading pictures

Four, sending network

1, write interface, send network

  • infileCreate in folderlogin.htmlFile and write the code below

  • Open the page in the browser

  • The inputThe user nameandpassword

  • Click on theThe login, you can see that willThe user nameandpasswordSent to thebaidu

2, import,TomcatIn the library

  • Because the server is the local machine, soformIn the tagactionSpecify as follows

  • Need to quoteTomcatThe two librariesjsp-api.jarandservlet-api.jar

  • Open the window below and selectDependenciesTo addLibrary...

  • Select the one previously configuredTomcat

  • Check selectedTomcat, click on theOK

  • At this point you can see the imported exterior in the projectTomcatlibrary

3. Send requests to the local server

  • insrcCreate in folderJava ClassThe type ofLoginServletFile, package name according to their own ideas

  • By default, enter it in a browserhttp://127.0.0.1:8080/hello, will visit the project01_HelloWorldIn thewebUnder folderindex.jspfile

  • At this point I added@WebServlet("/login")After, can passhttp://127.0.0.1:8080/hello/loginaccessLoginServletMethods in a class

  • inLoginServletClass to adddoGetanddoPostMethod and add a print statement to the method implementation

  • willlogin.htmlIn the fileformOf the labelactionModified to/hello/login, you can accessloginMethod, method type used ingetRequest, redeployWeb Application

  • Enter in the web pageThe user nameandpassword, 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 inIntelliJ IDEASee print indoGet

  • Change the method type topost, redeploy

  • Refresh the web page and enterThe user nameandpassword, click on theThe login

  • If the page goes blank, the request is successfully sent and no parameter is concatenated after the domain name
  • throughcheck, you can see that the parameter passesDataFormal transfer of

  • At this point, you can see the printdoPost

4. Respond to the request

  • inLoginServletFile, add response code, redeploy

  • The inputUser name: 123andPassword: 456

  • Click on theThe loginTo showLogin Success!

  • Go back to the input screen, enterUser name: 123andPassword: 4567

  • Click on theThe loginTo showLogin Failure!

4. Install Packet Tracer

1. Register the installation

  • Open the link: www.netacad.com/zh-hans/cou…

  • Scroll down and findSelf-paced learning online, click on theFor details

  • On the registration screen, selectcountriesandDate of birth

  • Fill in theRegistered 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 clickQuick start

  • Enter the password

  • When you clickCreate my accountThen, come to the following interface, this time the account has been registered

  • Slide to the bottom of the screen and clickPACKET TRACER

  • Find the version you need to download

  • Install and Log inCisco Packet TracerAfter, you can operate the following interface