JSP 鏈嶅姟鍣ㄥ搷搴

Response鍝嶅簲瀵硅薄涓昏灏咼SP瀹瑰櫒澶勭悊鍚庣殑缁撴灉浼犲洖鍒板鎴风銆傚彲浠ラ氳繃response鍙橀噺璁剧疆HTTP鐨勭姸鎬佸拰鍚戝鎴风鍙戦佹暟鎹紝濡侰ookie銆丠TTP鏂囦欢澶翠俊鎭瓑銆

涓涓吀鍨嬬殑鍝嶅簲鐪嬭捣鏉ュ氨鍍忎笅闈㈣繖鏍凤細

HTTP/1.1 200 OK
Content-Type: text/html
Header2: ...
...
HeaderN: ...
  (绌鸿)
<!doctype ...>
<html>
<head>...</head>
<body>
...
</body>
</html>

十分快三群聊—官方网址22270.COM鐘舵佽鍖呭惈HTTP鐗堟湰淇℃伅锛屾瘮濡侶TTP/1.1锛屼竴涓姸鎬佺爜锛屾瘮濡200锛岃繕鏈変竴涓潪甯哥煭鐨勪俊鎭搴旂潃鐘舵佺爜锛屾瘮濡侽K銆

涓嬭〃鎽樿鍑轰簡HTTP1.1鍝嶅簲澶翠腑鏈鏈夌敤鐨勯儴鍒嗭紝鍦ㄧ綉缁滅紪绋嬩腑鎮ㄥ皢浼氱粡甯歌鍒板畠浠細

鍝嶅簲澶 鎻忚堪
Allow 鎸囧畾鏈嶅姟鍣ㄦ敮鎸佺殑request鏂规硶锛圙ET锛孭OST绛夌瓑锛
Cache-Control 鎸囧畾鍝嶅簲鏂囨。鑳藉琚畨鍏ㄧ紦瀛樼殑鎯呭喌銆傞氬父鍙栧间负 publicprivate 鎴no-cache 绛夌瓑銆十分快三群聊—官方网址22270.COM Public鎰忓懗鐫鏂囨。鍙紦瀛橈紝Private鎰忓懗鐫鏂囨。鍙负鍗曠敤鎴锋湇鍔″苟涓斿彧鑳戒娇鐢ㄧ鏈夌紦瀛樸十分快三群聊—官方网址22270.COMNo-cache 鎰忓懗鐫鏂囨。涓嶈缂撳瓨銆
Connection 鍛戒护娴忚鍣ㄦ槸鍚﹁浣跨敤鎸佷箙鐨凥TTP杩炴帴銆close 鍛戒护娴忚鍣ㄤ笉浣跨敤鎸佷箙HTTP杩炴帴锛岃宬eep-alive 鎰忓懗鐫浣跨敤鎸佷箙鍖栬繛鎺ャ
Content-Disposition 璁╂祻瑙堝櫒瑕佹眰鐢ㄦ埛灏嗗搷搴斾互缁欏畾鐨勫悕绉板瓨鍌ㄥ湪纾佺洏涓
Content-Encoding 鎸囧畾浼犺緭鏃堕〉闈㈢殑缂栫爜瑙勫垯
Content-Language 琛ㄨ堪鏂囨。鎵浣跨敤鐨勮瑷锛屾瘮濡俥n锛 en-us,锛宺u绛夌瓑
Content-Length 琛ㄦ槑鍝嶅簲鐨勫瓧鑺傛暟銆傚彧鏈夊湪娴忚鍣ㄤ娇鐢ㄦ寔涔呭寲 (keep-alive) HTTP 杩炴帴鏃舵墠鏈夌敤
Content-Type 琛ㄦ槑鏂囨。浣跨敤鐨凪IME绫诲瀷
Expires 鎸囨槑鍟ユ椂鍊欒繃鏈熷苟浠庣紦瀛樹腑绉婚櫎
Last-Modified 鎸囨槑鏂囨。鏈鍚庝慨鏀规椂闂淬傚鎴风鍙互 缂撳瓨鏂囨。骞朵笖鍦ㄥ悗缁殑璇锋眰涓彁渚涗竴涓 If-Modified-Since璇锋眰澶
Location 鍦300绉掑唴锛屽寘鍚墍鏈夌殑鏈変竴涓姸鎬佺爜鐨勫搷搴斿湴鍧锛屾祻瑙堝櫒浼氳嚜鍔ㄩ噸杩炵劧鍚庢绱㈡柊鏂囨。
Refresh 鎸囨槑娴忚鍣ㄦ瘡闅斿涔呰姹傛洿鏂颁竴娆¢〉闈€
Retry-After 涓503 (Service Unavailable)涓璧蜂娇鐢ㄦ潵鍛婅瘔鐢ㄦ埛澶氫箙鍚庤姹傚皢浼氬緱鍒板搷搴
Set-Cookie 鎸囨槑褰撳墠椤甸潰瀵瑰簲鐨刢ookie

httpervletResponse绫

response 瀵硅薄鏄 javax.servlet.http.httpervletResponse 绫荤殑涓涓疄渚嬨十分快三群聊—官方网址22270.COM灏卞儚鏈嶅姟鍣ㄤ細鍒涘缓request瀵硅薄涓鏍凤紝瀹冧篃浼氬垱寤轰竴涓鎴风鍝嶅簲銆

response瀵硅薄瀹氫箟浜嗗鐞嗗垱寤篐TTP淇℃伅澶寸殑鎺ュ彛銆傞氳繃浣跨敤杩欎釜瀵硅薄锛屽紑鍙戣呬滑鍙互娣诲姞鏂扮殑cookie鎴栨椂闂存埑锛岃繕鏈塇TTP鐘舵佺爜绛夌瓑銆

涓嬭〃鍒楀嚭浜嗙敤鏉ヨ缃瓾TTP鍝嶅簲澶寸殑鏂规硶锛岃繖浜涙柟娉曠敱httpervletResponse 绫绘彁渚涳細

S.N. 鏂规硶 & 鎻忚堪
1 String encodeRedirectURL(String url)

瀵箂endRedirect()鏂规硶浣跨敤鐨刄RL杩涜缂栫爜
2 String encodeURL(String url)

灏哢RL缂栫爜锛屽洖浼犲寘鍚玈ession ID鐨刄RL
3 boolean containsHeader(String name)

杩斿洖鎸囧畾鐨勫搷搴斿ご鏄惁瀛樺湪
4 boolean isCommitted()

杩斿洖鍝嶅簲鏄惁宸茬粡鎻愪氦鍒板鎴风
5 void addCookie(Cookie cookie)

娣诲姞鎸囧畾鐨刢ookie鑷冲搷搴斾腑
6 void addDateHeader(String name, long date)

娣诲姞鎸囧畾鍚嶇О鐨勫搷搴斿ご鍜屾棩鏈熷
7 void addHeader(String name, String value)

娣诲姞鎸囧畾鍚嶇О鐨勫搷搴斿ご鍜屽
8 void addIntHeader(String name, int value)

娣诲姞鎸囧畾鍚嶇О鐨勫搷搴斿ご鍜宨nt鍊
9 void flushBuffer()

灏嗕换浣曠紦瀛樹腑鐨勫唴瀹瑰啓鍏ュ鎴风
10 void reset()

娓呴櫎浠讳綍缂撳瓨涓殑浠讳綍鏁版嵁锛屽寘鎷姸鎬佺爜鍜屽悇绉嶅搷搴斿ご
11 void resetBuffer()

娓呴櫎鍩烘湰鐨勭紦瀛樻暟鎹紝涓嶅寘鎷搷搴斿ご鍜岀姸鎬佺爜
12 void sendError(int sc)

浣跨敤鎸囧畾鐨勭姸鎬佺爜鍚戝鎴风鍙戦佷竴涓嚭閿欏搷搴旓紝鐒跺悗娓呴櫎缂撳瓨
13 void sendError(int sc, String msg)

浣跨敤鎸囧畾鐨勭姸鎬佺爜鍜屾秷鎭悜瀹㈡埛绔彂閫佷竴涓嚭閿欏搷搴
14 void sendRedirect(String location)

浣跨敤鎸囧畾鐨刄RL鍚戝鎴风鍙戦佷竴涓复鏃剁殑闂存帴鍝嶅簲
15 void setBufferSize(int size)

璁剧疆鍝嶅簲浣撶殑缂撳瓨鍖哄ぇ灏
16 void setCharacterEncoding(String charset)

鎸囧畾鍝嶅簲鐨勭紪鐮侀泦锛圡IME瀛楃闆嗭級锛屼緥濡俇TF-8
17 void setContentLength(int len)

鎸囧畾HTTP servlets涓搷搴旂殑鍐呭鐨勯暱搴︼紝姝ゆ柟娉曠敤鏉ヨ缃 HTTP Content-Length 淇℃伅澶
18 void setContentType(String type)

璁剧疆鍝嶅簲鐨勫唴瀹圭殑绫诲瀷锛屽鏋滃搷搴旇繕鏈鎻愪氦鐨勮瘽
19 void setDateHeader(String name, long date)

浣跨敤鎸囧畾鍚嶇О鍜屽艰缃搷搴斿ご鐨勫悕绉板拰鍐呭
20 void setHeader(String name, String value)

浣跨敤鎸囧畾鍚嶇О鍜屽艰缃搷搴斿ご鐨勫悕绉板拰鍐呭
21 void setIntHeader(String name, int value)

鎸囧畾 int 绫诲瀷鐨勫煎埌 name 鏍囧ご
22 void setLocale(Locale loc)

璁剧疆鍝嶅簲鐨勮瑷鐜锛屽鏋滃搷搴斿皻鏈鎻愪氦鐨勮瘽
23 void setStatus(int sc)

璁剧疆鍝嶅簲鐨勭姸鎬佺爜

HTTP鍝嶅簲澶寸▼搴忕ず渚

鎺ヤ笅鏉ョ殑渚嬪瓙浣跨敤setIntHeader()鏂规硶鍜宻etRefreshHeader()鏂规硶鏉ユā鎷熶竴涓暟瀛楁椂閽燂細

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>闄曡タ蹇笁鍊嶆姇鎶宸 鈥旈椤-楦熸暀绋(alevg.com)</title>
</head>
<body>
<h2>鑷姩鍒锋柊瀹炰緥</h2>
<%
   // 璁剧疆姣忛殧5绉掕嚜鍔ㄥ埛鏂
   response.setIntHeader("Refresh", 5);
   // 鑾峰彇褰撳墠鏃堕棿
   Calendar calendar = new GregorianCalendar();
   String am_pm;
   int hour = calendar.get(Calendar.HOUR);
   int minute = calendar.get(Calendar.MINUTE);
   int second = calendar.get(Calendar.SECOND);
   if(calendar.get(Calendar.AM_PM) == 0)
      am_pm = "AM";
   else
      am_pm = "PM";
   String CT = hour+":"+ minute +":"+ second +" "+ am_pm;
   out.println("褰撳墠鏃堕棿: " + CT + "\n");
%>
</body>
</html>

灏嗕互涓婁唬鐮佷繚瀛樹负main.jsp锛岀劧鍚庨氳繃娴忚鍣ㄨ闂畠銆傚畠灏嗕細姣忛殧5绉掓樉绀轰竴涓嬬郴缁熷綋鍓嶆椂闂淬

鎴戜滑鍙互鐪嬩笅浠ヤ笅 Gif 婕旂ず鍥撅細

鎮ㄤ篃鍙互鑷繁鍔ㄦ墜淇敼浠ヤ笂浠g爜锛岃瘯璇曚娇鐢ㄥ叾浠栫殑鏂规硶锛屽皢鑳藉緱鍒版洿娣辩殑浣撲細銆