Hackforge Academy

Category: java

request and response handling

Published on 30 Sep 2026

Explanation

HttpServletRequest provides information about the incoming HTTP request, while HttpServletResponse is used to construct the response.

Code:

doGet(HttpServletRequest request,
      HttpServletResponse response) {

    // request β†’ client information
    // response β†’ server response
}

Explanation

Read request information such as HTTP method, URI, and client information from HttpServletRequest.

Code:

String method = request.getMethod();
String uri = request.getRequestURI();
String ip = request.getRemoteAddr();

Explanation

Set the response content type before writing data to the client.

Code:

response.setContentType("text/html");

PrintWriter out = response.getWriter();
out.println("<h1>Hello</h1>");

Explanation

Set HTTP status codes to indicate the result of request processing.

Code:

response.setStatus(HttpServletResponse.SC_OK);

// Example error
response.sendError(
    HttpServletResponse.SC_NOT_FOUND,
    "User not found"
);

Explanation

Redirect the client to another URL using sendRedirect().

Code:

response.sendRedirect("login.html");

πŸš€ Learn Spring Boot with real-world projects

πŸ’‘ Build REST APIs step by step

🧠 Improve backend development skills

🎯 Get career-ready practical training

Join Our Free WhatsApp Community

Direct access to niche-specific mentors and peers on WhatsApp.

🐍

Python Community

Discuss Django, FastAPI, AI integration, and automation scripts with 15k+ developers.

Join Python Community
βš›οΈ

React Community

Master Next.js, Framer Motion, and State Management. Share your latest UI components.

Join React Community
β˜•

Java Community

Deep dives into Spring Boot, Microservices architecture, and high-performance backend ops.

Join Java Community