è¦èªå¨çæéæ页é¢ï¼ç¨Filteræªè·jsp请æ±å¹¶å
è¿è¡é¢å¤çï¼èªå¨çæHtmlï¼æ¯ä¸ªä¸éç主æãä¸ä¸ªå¾å®¹ææ³å°çæ¹æ³æ¯å¨Filteræªè·Requeståï¼ï¼å¯¼åä¸ä¸ªServletï¼å¨è¿ä¸ªServletä¸åæ¬æºåéä¸ä¸ªhttp请æ±ï¼ç¶åå°ååºåå
¥ä¸ä¸ªæ件ï¼
URLConnection urlConn = URLConnection.open();
注æè¦é¿å
éå½ã
å¦ä¸ä¸ªæ¹æ³æ¯ä¸æ¨¡æhttpï¼èæ¯å®å¶Responseï¼ææå¡å¨è¿åçJSPååºè¾åºå°æ们èªå·±çResponseä¸ï¼å°±å¯ä»¥å°ååºå¿«éåå
¥Htmlæ件ï¼ç¶åååéç»å®¢æ·ãèä¸ï¼ç±äºæ²¡æhttp模æ请æ±ï¼ç´æ¥è¯»åæå¡å¨ååºé度é常快ã
æªè·Responseçå
³é®ä¾¿æ¯å®ç°ä¸ä¸ªWrappedResponseï¼è®©æå¡å¨å°ååºåå
¥æ们çWrappedResponseä¸ãè¿ç±»ä¼¼äºä¸ä¸ªä»£ç模å¼ï¼Servlet 2.xå·²ç»æä¾äºä¸ä¸ªWrappedResponseç±»ï¼æ们åªéè¦å¤åå
¶ä¸çä¸äºå
³é®æ¹æ³å³å¯ã
WrappedResponseå®ç°äºResponseæ¥å£ï¼å®éè¦ä¸ä¸ªResponseä½ä¸ºæé å½æ°çåæ°ï¼äºå®ä¸è¿æ£æ¯ä»£ç模å¼çåºç¨ï¼WrappedResponseå
å½äºä»£çè§è²ï¼å®ä¼å°JSP/Servlet容å¨çæäºæ¹æ³è°ç¨è¿è¡é¢å¤çï¼æ们éè¦å®ç°èªå·±çæ¹æ³ã
综ä¸ï¼ç¨Filterå®ç°HTMLç¼å²çæ¥éª¤æ¯ï¼
1. ç¨Filteræªè·è¯·æ±ï¼å¦/a.jsp?id=123ï¼æ å°å°å¯¹åºçhtmlæ件å为/html/a.jspid=123.htmã
2. æ¥æ¾æ¯å¦æ/html/a.jspid=123.htmï¼å¦ææï¼ç´æ¥forwardå°æ¤htmlï¼ç»æã
3. å¦æ没æï¼å®ç°ä¸ä¸ªWrappedResponseï¼ç¶åè°ç¨filterChain(request, wrappedResponse)ã
4. å°è¿åçWrappedResponseåå
¥æ件/html/a.jspid=123.htmï¼ç¶åè¿åååºç»ç¨æ·ã
5. ä¸ä¸æ¬¡ç¨æ·åéç¸åç请æ±æ¶ï¼å°ç¬¬2æ¥å°±ç»æäºã
使ç¨è¿ä¸ªæ¹æ³ç好å¤æ¯ä¸ç¨æ´æ¹ç°æçServletï¼JSP页ï¼éå¶æ¯ï¼JSP页é¢ç»æä¸è½ä¸Sessionç¸å
³ï¼éè¦ç»éæç¨æ·å®å¶ç页é¢ä¸è½ç¨è¿ç§æ¹æ³ç¼å²ã
温馨提示:答案为网友推荐,仅供参考