How can I implement this mapping programmatically without web.xml or annotations? The mission is not to use any framework like spring or something else.
<
You can use annotations to achieve this using code.
import java.io.IOException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/hello")
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.getWriter().println("Hello");
}
}
You can read about annotations here, here and here