- 상태코드
- 헤더세팅
- content
- cookie
- redirect
상태코드
response.setStatus(HttpServletResponse.SC_OK);
헤더세팅
response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setHeader("my-header", "hello");
헤더 세팅시 편의 메서드
content
private void content(HttpServletResponse response) {
//Content-Type: text/plain;charset=utf-8
//Content-Length: 2
//response.setHeader("Content-Type", "text/plain;charset=utf-8");
response.setContentType("text/plain");
response.setCharacterEncoding("utf-8");
//response.setContentLength(2); //(생략시 자동 생성)
}
cookie
private void cookie(HttpServletResponse response) {
// Set-Cookie: myCookie=good; Max-Age=600;
// response.setHeader("Set-Cookie", "myCookie=good; Max-Age=600");
Cookie cookie = new Cookie("myCookie", "good");
cookie.setMaxAge(600); //600초
response.addCookie(cookie);
}
redirect
private void redirect(HttpServletResponse response) throws IOException {
//Status Code 302
//Location: /basic/hello-form.html
// response.setStatus(HttpServletResponse.SC_FOUND); //302
// response.setHeader("Location", "/basic/hello-form.html");
response.sendRedirect("/basic/hello-form.html");
}
'Web > MVC' 카테고리의 다른 글
EP5. Spring MVC 기본 기능 (요청 매핑) (0) | 2021.03.25 |
---|---|
EP4. 스프링 MVC 구조 (0) | 2021.03.25 |
EP4. MVC 패턴 (0) | 2021.03.22 |
EP2. 서블릿객체만을 이용해 HTTP 요청데이터 처리하기 (0) | 2021.03.18 |
EP1. WAS, 서블릿, 멀티쓰레드 (0) | 2021.03.17 |