Build a server that implements simple functions
- basic knowledge
- Realize function
- Realization idea
- Show results
-
- Use default port, default error page, default welcome page, service without servlet
- Use configuration files to customize ports, custom error pages, custom welcome pages, and servlet-free services
- Test Servlet forwarding function
- Test Servlet redirection function
- Multi-parameter acquisition test
- Simple login function to test parameter acquisition and forwarding function according to the request method
- Code acquisition
basic knowledge
- XML, HTML
- Object-oriented
- String、StringBuilder
- Multithreading
- SAX XML reading
- reflection
- Singleton mode
Realize function
- Encapsulate Request to realize the function of forwarding and obtaining parameters
- Encapsulate Response to implement simple external web page redirection
- Custom server port, error page, welcome page
- Declare Servlet and ServletMapping in the prescribed format
- Support GET method to pass parameters
- Support POST URLencoded form data method to pass parameters
Realization idea
Project structure diagram
The implementation is relatively long. If you are interested, please see the implementation ideas of Java basic-blank server.
This article looks at the implementation effect
Show results
Use default port, default error page, default welcome page, service without servlet
Use configuration files to customize ports, custom error pages, custom welcome pages, and servlet-free services
Test Servlet forwarding function
Test Servlet redirection function
Multi-parameter acquisition test
Simple login function to test parameter acquisition and forwarding function according to the request method
Code acquisition
GitHub code hosting If you
are interested, you can take a look. Any bugs are purely normal.