jsp request sessionµÈ¶ÔÏó Ïê½â
jsp request session
µÈ¶ÔÏó
Ïê½â
תÕß×¢£º´ËÎÄ×ܽá½ÏΪÏêϸ£¬ÖµµÃ²Î¿¼¡£µ«²¿·ÖÄÚÈݾ¹ýÕûÀí£¬ÒÔÏÂÊÇÕýÎÄ¡£
1.request
¶ÔÏó
ÕâÁ½¸ö¶ÔÏóÊÇASPËùÌṩµÄÄÚÖöÔÏóÖÐ×î³£ÓõÄÁ½¸ö¡£ÔÚä¯ÀÀÆ÷£¨»òÆäËûÓû§´úÀí£©ºÍWeb·þÎñÆ÷Ö®¼ä£¬ÇëÇóÓëÏìÓ¦Öз¢ÉúµÄÐÅÏ¢½»Á÷¿ÉÒÔͨ¹ýASPÖеÄÁ½¸öÄÚÖöÔÏóÀ´½øÐзÃÎʺ͹ÜÀí£¬ÕâÁ½¸ö¶ÔÏó³ÆΪRequestºÍResponse¶ÔÏó¡£
¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚ
request
¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇ
HttpServletRequest
ÀàµÄʵÀý¡£
(1)Attribute
ÉèÖÃ
£¨
get
»ò
set
£©
object getAttribute(String name)
·µ»Ø
name
Ö¸¶¨µÄÊôÐÔÖµ£¬Èç¹ûÖ¸¶¨µÄÊôÐÔÖµ²»´æÔÚ£¬Ôò»á·µ»Ø
null
Öµ£®
Enumeration getAttributeNames()
·µ»Ø
request
¶ÔÏóµÄËùÓÐÊôÐÔµÄÃû×Ö£¬Æä½á¹ûÊÇÒ»¸öÀà¾Ù£¨
Enumeration
£©ÀàµÄʵÀý£®
void setAttribute( String name ,
java.lang.Object objt )
ÉèÖÃÃû×ÖΪ
name
µÄ
request
²ÎÊýµÄÖµ£¬¸ÃÖµÊÇÓÉ
java.lang.Object
ÀàÐ͵Ä
objt
Ö¸¶¨
(2) Parameter
String getParameter( String name )
»ñµÃ¿Í»§¶Ë´«Ë͸ø·þÎñÆ÷µÄ²ÎÊýÖµ£¬¸Ã²ÎÊýÊÇÓÉ
name
Ö¸¶¨µÄ£®
Enumeration getParameterNames()
·µ»Ø¿Í»§¶Ë´«¸ø·þÎñÆ÷ÕªµÄËùÓвÎÊýµÄÃû×Ö£¬Æä½á¹ûÒ²ÊÇÒ»¸öÀà¾ÙÀàµÄʵÀý£®
String [] getParameterValues( String name )
»ñµÃÖ¸¶¨²ÎÊýµÄËùÓÐÖµ£¬²ÎÊýÓÉ
name
Ö¸¶¨£®
(3) Method
getMethod()
»ñµÃ¿Í»§¶ËÏò·þÎñÆ÷¶Ë´«ËÍÊý¾ÝµÄ·½·¨£¬Èç
get,post
µÈ£®
(4)
¿Í»§¶ËºÍ·þÎñÆ÷Ö®¼äµÄ
Protocol
×å
String getProtocol()
·µ»ØÇëÇóÓõÄÐÒéÀàÐͼ°°æ±¾ºÅ
String getServerName()
·µ»Ø½ÓÊÜÇëÇóµÄ·þÎñÆ÷Ö÷»úÃû
int getServerPort()
·µ»Ø·þÎñÆ÷½ÓÊÜ´ËÇëÇóËùÓõĶ˿ںÅ
String getRemoteAddr()
·µ»Ø·¢ËÍ´ËÇëÇóµÄ¿Í»§¶Ë
IP
µØÖ·
String getRemoteHost()
·µ»Ø·¢ËÍ´ËÇëÇóµÄ¿Í»§¶ËÖ÷»úÃû
getRequestURI()
»ñÈ¡·¢³öÇëÇó×Ö·û´®µÄ¿Í»§¶ËµÄµØÖ·£®
(5) Header
getHeader( String name )
·µ»ØÖ¸¶¨Ãû×ÖµÄ
request Header
µÄËùÓÐÖµ£¬Æä½á¹ûÒ²ÊÇÒ»¸öÀà¾ÙÀàµÄʵÀý£®
getHeaderNames()
·µ»ØËùÓÐ
request Header
µÄÃû×Ö£¬Æä½á¹ûÒ²ÊÇÒ»¸öÀà¾ÙÀàµÄʵÀý£®
(6)
ÆäËû
String getCharacterEncoding()
·µ»Ø×Ö·û±àÂ뷽ʽ
int getContentLeng
Ïà¹ØÎĵµ£º
Ê×ÏÈÊÇÌá½»Ò³Ã棺Èý¸ö±íµ¥(form1,form2,form3)
<form name="form1" method="post" action="checklogin.jsp" class="niceform">
<input name="qx" type="hidden" value="3">
&nb ......
ÎÒÃÇÔÚдһ¸öjspÒ³Ã棬ҪʹÓÃstruts2±êÇ©£¬ÎÒÃÇÒªÊ×ÏÈÒªÔÚjspÒ³ÃæÍ·²¿·Å£º<%@ taglib prefix="s" uri="/struts-tags" %>£¬µ±È»Òª·Åstruts2µÄjar°üÁË¡£ÎÒÃÇ¿ÉÒÔË¢ÐÂһϴËÒ³Ã棬±ÈÈç°ÑÕâ¸öÒ³Ãæ±£´æºóÔÙ´ò¿ª£¬Ä¿µÄÊÇÔÚдstruts2±êǩʱ£¬ÓÐstruts2±êÇ©×Ô¶¯Ìáʾ¹¦ÄÜ¡£
......
private String projectName="sz_pro"; // ÄãÏîÄ¿µÄÃû³Æ
//»ñÈ¡µ±Ç°ÏîÄ¿µÄ¾ø¶Ô·¾¶
public String getPorjectPath(){
String nowpath; //µ±Ç°tomcatµÄbi ......
ÔÚjspÖУ¬Èç¹ûÔÚurlÖд«µÝÖÐÎÄʱ»á³öÏÖÂÒÂ룬ÔÚÍøÉϹØÓÚÕâÒ»ÎÊÌâµÄ½â¾ö·½·¨Î廨°ËÃÅ£¬µ«¶¼²»ÊǺÜ×àЧ£¡Æäʵ½â¾ö·½·¨·Ç³£¼òµ¥£º µÚÒ»²½£º±àÂ루ÒÔ´«µÝµÄ²ÎÊýΪstrΪÀý£© ÔÚ´«µÝÊý¾ÝÇ°½«str½øÐбàÂëJava.net.URLEncoder.encode(str) µÚ¶þ²½£º½âÂë ÔÚ»ñÈ¡Êý¾Ý¶Ë½«µÃµ½µÄÊý¾Ý½øÐнâÂë new String£¨str.getBytes("ISO8859_1")£©
......
GBK±àÂë
GBK±àÂëÊÇÖйúÖƶ©µÄ¡¢µÈͬÓÚUCSµÄеÄÖÐÎıàÂëÀ©Õ¹¹ú¼Ò±ê×¼¡£GBK¹¤×÷С×éÓÚ1995Äê10Ô£¬Í¬Äê12ÔÂÍê³ÉGBK¹æ·¶¡£¸Ã±àÂë±ê×¼¼æÈÝGB2312£¬¹²ÊÕ¼ºº×Ö21003¸ö¡¢·ûºÅ883¸ö£¬²¢Ìṩ1894¸öÔì×ÖÂë룬¼ò¡¢·±Ìå×ÖÈÚÓÚÒ»¿â¡£
UTF-8±àÂë
UTF-8±àÂë¿ÉÒÔͨ¹ýÆÁ±ÎλºÍÒÆλ²Ù×÷¿ìËÙ¶Áд¡£×Ö·û´®±È½Ïʱstrcmp()ºÍ
wcscmp()µÄ· ......