stm32+w5500 implements web service _java implements a simple web server

ORIGINAL POST
By weixin_39774219
details

4b7fd6c663c1e8809c67949bf871210b.jpg

web server
A web server, also known as a hypertext transfer protocol server, uses http to communicate with its clients. A java-based web server uses two important classes,

. First java.net.Socket class and java.net.ServerSocket class, and communicate based on sending http messages.
step 1;
The entry of the application is in the HttpServer class. The main() method creates an HttpServer instance and then calls its await() method. As the name suggests, the await() method will wait for the HTTP request on the specified port, process it, and then send the response information Back to the client, it will remain in a wait state until it receives a close command.
The Request class represents an HTTP request. You can pass an InputStream object to create a Request object, and you can call the read() method in the InputStream object to read the raw data of the HTTP request.

The parse() method in the above source code is used to parse the raw data of the Http request. The parse() method will call the private method parseUrI() to parse the URI of the HTTP request. In addition, it does not do much work. parseUri( ) method stores the URI in the variable uri, and calling the public method getUri() returns the requested uri.

The Response object is created in the await() method of the HttpServer class by passing in the OutputStream obtained from the socket.

The Response class has two public methods: setRequest() and sendStaticResource(). The setRequest() method will receive a Request object as a parameter, and the sendStaticResource() method is used to send a static resource to the browser, such as an Html file.

This class represents a web server that can handle requests for static resources in a specified directory, including the directory and all its subdirectories specified by the public static variable final WEB_ROOT.

Now create an html page in webroot, named index.html, the source code is as follows

 

———————————————
Copyright statement: This article is an original article by CSDN blogger “weixin_39774219” and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/weixin_39774219/article/details/111332297

4b7fd6c663c1e8809c67949bf871210b.jpg

web server
A web server, also known as a hypertext transfer protocol server, uses http to communicate with its clients. A java-based web server uses two important classes,

. First java.net.Socket class and java.net.ServerSocket class, and communicate based on sending http messages.
step 1;
The entry of the application is in the HttpServer class. The main() method creates an HttpServer instance and then calls its await() method. As the name suggests, the await() method will wait for the HTTP request on the specified port, process it, and then send the response information Back to the client, it will remain in a wait state until it receives a close command.
The Request class represents an HTTP request. You can pass an InputStream object to create a Request object, and you can call the read() method in the InputStream object to read the raw data of the HTTP request.

The parse() method in the above source code is used to parse the raw data of the Http request. The parse() method will call the private method parseUrI() to parse the URI of the HTTP request. In addition, it does not do much work. parseUri( ) method stores the URI in the variable uri, and calling the public method getUri() returns the requested uri.

The Response object is created in the await() method of the HttpServer class by passing in the OutputStream obtained from the socket.

The Response class has two public methods: setRequest() and sendStaticResource(). The setRequest() method will receive a Request object as a parameter, and the sendStaticResource() method is used to send a static resource to the browser, such as an Html file.

This class represents a web server that can handle requests for static resources in a specified directory, including the directory and all its subdirectories specified by the public static variable final WEB_ROOT.

Now create an html page in webroot, named index.html, the source code is as follows

 

———————————————
Copyright statement: This article is an original article by CSDN blogger “weixin_39774219” and follows the CC 4.0 BY-SA copyright agreement. Please attach the original source link and this statement for reprinting.
Original link: https://blog.csdn.net/weixin_39774219/article/details/111332297

COMMENTS

Please Login to comment
  Subscribe  
Notify of
POSTED BY
Reusable S/W