Notice
Recent Posts
Recent Comments
Link
«   2025/01   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

개발자되기 프로젝트

HTTP 응답 데이터 - 단순 텍스트, HTML 본문

인프런/[인프런] 스프링 MVC 1

HTTP 응답 데이터 - 단순 텍스트, HTML

Seung__ 2021. 9. 8. 23:00

1. HTTP 응답 메시지는 주로 아래 내용을 담아서 전달됨.


  • 단순 텍스트 응답
    •  writer.println("ok");
  • HTML 응답
  • HTTP API - MessageBody JSON 응답

 

 

2. HttpServletResponse - HTML 응답


  • content-type : text/html 
@WebServlet(name = "ResponseHtmlServlet", urlPatterns = "/response-html")
public class ResponseHtmlServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        //Content-Type: text/html;charset=utf-8
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");

        PrintWriter writer = response.getWriter();
        writer.println("<html>");
        writer.println("<body>");
        writer.println("    <div>안녕</div>");
        writer.println("</body>");
        writer.println("</html>");
    }
}

 

 

3. GitHub : 210908 HttpServletResponse, html


 

GitHub - bsh6463/MVC1

Contribute to bsh6463/MVC1 development by creating an account on GitHub.

github.com

 

Comments