sungwony

[웹프로그래밍] 리프래시 / 리다이렉트 본문

development/웹프로그래밍

[웹프로그래밍] 리프래시 / 리다이렉트

일상이상삼상 2017. 5. 23. 10:40

'리프래시(Refresh)'

: 일정 시간이 지나고 나서 자동으로 서버에 요청을 보내는 방법


1) 응답 헤더를 활용한 리프래시


response.addHeader("Refresh", "1;url=list");


응답 정보를 살펴보면


HTTP/1.1 200 OK

Server: ...

Refresh: 1;url=test

...


'Refresh' 헤더 값의 숫자 '1'은 응답 본문을 출력하고 나서 1초 뒤에 다시 서비스를 요청하라는 뜻. 이때 url은 다시 요청할 서비스 주소.


2) HTML의 meta 태그를 이용한 리프래시

PrintWriter out = response.getWriter();

out.println("<html><head>"

out.println("<meta http-equiv='Refresh' content='1'; url=test'>");

out.println("</head><body></body></html>");



'리다이랙트(Redirect)'

: 클라이언트에서 결과를 출력하지 않고 다른 페이지로 이동하는 방법


1) 리다이렉트 메서드 sendRedirect()


response.sendRedirect("test");


응답 정보

HTTP/1.1 302 Found

Server: ...

Location: http://localhost:8080/webTest/test

Content-Length: 0

Date: ...


Location에 기재된 URL로 다시 요청을 보낸다.