> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/mvc/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/mvc/undefined-1/hello.md).

# Hello 서블릿

톰캣이나 여러 WAS 서버가 많다. HttpServletRequest와 HttpServletResponse는 인터페이스인 것을 확인할 수 있다. 그러므로 이 인터페이스를 구현한 구현체들이 존재한다.

request 객체와 resonse 객체를 출력해보면 다음과 같이 확인해볼 수 있다.

웹 애플리케이션 서버(WAS)의 요청 응답 구조

![](/files/-MduGvPe57ycnhDUJa8Z)

WAS에서 request, response를 생성하고, 서블릿 컨테이너의 helloServlet을 실행한다! helloServlet이 종료되고 나면 Response 객체 정보로 HTTP 응답을 생성한다!

@WebserVlet 애노테이션 추가, 서블릿 이름과 url을 값으로 함께 넣어준다.\
public class HeelloServlet이 실행되면서 이것은 HttpServlet을 상속 받는다!

```java
package hello.servlet.basic;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name="helloServlet", urlPatterns ="/hello")
public class HelloServlet extends HttpServlet {//HttpServlet을 상속받는다!
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("HelloServlet.service");
        System.out.println("request = " + request);
        System.out.println("response = " + response);

        String username = request.getParameter("username");
        System.out.println("username = " + username);

        response.setContentType("text/plain");
        response.setCharacterEncoding("utf-8");//인코딩 정보 알려줘야함!
        response.getWriter().write("hello"+username);//http응답 메시지 바디에 들어간다!

    }

}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://heunnajo.gitbook.io/mvc/undefined-1/hello.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
