Java Web knowledge essential

Keywords: Java Front-end

Java Web knowledge essential

web concept review

  • Software architecture
    1. C/S: client / server
    2. B/S: Browser / server
  • Resource classification
    1. Static resource: all users get the same result after accessing, which is called static resource. Static resources can be directly parsed by the browser, such as html, css and JavaScript
    2. Dynamic resources: each user may get different results after accessing the same resources. It is called dynamic resource. After the dynamic resources are accessed, they need to be converted to static resources, such as servlet, jsp and php
  • Three elements of network communication
    1. IP
    2. Port number
    3. transport protocol

web server software

  • Server: the computer on which the server software is installed
  • Server software: receive the user's request, process the request and respond
  • web server software: receive the user's request, process the request and respond
    • In web server software, web projects can be deployed to allow users to access these projects through a browser
    • web container
  • Common java related web server software
    • Tomcat: Apache Foundation
      • Tomact file
      • Tomact startup:
        • bin/startup.bat, double-click to run the file
        • Access: Browser input: http: / /
      • to configure:
        • Just put the project under webapps
        • Simple deployment: package the project into a war package, and then place the war package in the webapps directory. The war package will be decompressed automatically

Servlet: server applet

  • Concept: applet running on the server
    • Servlet is an interface that defines the rules for JAVA classes to be accessed by the browser (recognized by tomact)
    • In the future, we will customize a class to implement Servlet interface and replication method
  • quick get start
    1. Create JAVA EE project
    2. Define a class to implement Servlet
    3. Implementing abstract methods in interfaces
    4. Configure Servlet (in web.xml)


Concept: Hyper Text Transfer Protocol
*Transmission protocol: defines the format of data sent when the client and server communicate
1. Advanced protocol based on TCP/IP
2. Default port number: 80
3. Based on request response model: one request and one response
4. Stateless: each request is independent of each other and cannot interact with data
Request message data format
1. Request line
Request mode request URL request protocol / version
GET /login.html HTTP/1.1
*Request method:
*HTTP protocol has seven request modes, two of which are commonly used
* GET:
1. The request parameter is in the request line, after the URL
2. The length of the requested URL is limited
1. The request parameter is in the request body
2. The length of the requested URL is unlimited
2. Request header: the client browser tells the server to access the information of the browser used
3. Request blank line: used to split the request header and request body of a POST request
4. Request body: the request parameter that encapsulates the POST request information

Request :

    1. The Request object and the reply object are created by the server, and we use them
    2. The Request object is used to get the Request message, and the Response object is used to set the Response message
  • Request function
    1. Get request line data
    2. Get request header data
    3. Get request body data

Request line

String method = req.getMethod();//Get request method
        String contextPath = req.getContextPath();//Get virtual path
        String servletPath = req.getServletPath();//Get Servlet path
        String queryString = req.getQueryString();//Get request parameters
        String requestURI = req.getRequestURI();//Gets the URI of the request
        String protocol = req.getProtocol();//Get protocol version
        String remoteAddr = req.getRemoteAddr();//Get the ip address of the client

Request header

public class RequestDemo04 extends HttpServlet {
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //Get header
        String header = req.getHeader("user-agent");
        else if(header.contains("Firefox"))

Request body

  • Only the POST mode has a request body, which encapsulates the request parameters of the POST request
  • step
    • Get stream object
    • Then get the data from the stream object

BeanUtils tool class to simplify data encapsulation

  • JAVABean: standard JAVA class
    • requirement
      • Class must be public decorated
      • Constructor that must provide null arguments
      • Member variables must be decorated with private
      • Provide public setter s and Getters
    • Function: encapsulate data
    • Properties, not member variables, are manipulated
      Continuous update~~~

Posted by Lexi on Thu, 11 Nov 2021 21:28:45 -0800