Handle the POST request

Report a typo

The HttpExchange class is responsible for storing the request and response data. In this task, you'll find its implementation that stores the request URI and the request body as a JSON with a single property.

Implement the handle() method to process a similar request and print a string with the The response from {URI} is Hello, {name} syntax.

Sample Input 1:

Mark

Sample Output 1:

The response from localhost:8000/person is Hello, Mark
Write a program in Java 17
import com.sun.net.httpserver.*;

import java.io.*;
import java.net.*;
import java.util.Scanner;

class MyHttpHandler implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {

}
}

public class Main {
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);

MyHttpHandler handler = new MyHttpHandler();
handler.handle(generateHttpExchange(scanner.nextLine()));
}

public static HttpExchange generateHttpExchange(String name) {
return new HttpExchange() {
@Override
public Headers getRequestHeaders() {
return null;
}

@Override
public Headers getResponseHeaders() {
return null;
}

@Override
public URI getRequestURI() {
try {
___

Create a free account to access the full topic