天天看点

javaWeb数据区内置对象

??缃?瀵硅薄

request???$???ユ?跺?㈡?风??浠?ttp?瑰?浼???杩??ョ???版??

javaWeb数据区内置对象

?歌?浜??朵???缃?瀵硅薄 reques???????板???卞?㈡?风???峰??杈??ユ?版?? 涓?瀹???string绫诲??

???????$??璺宠浆?ㄦ???藉?ㄩ〉????翠?????瀹㈡?风??涓?琛?

灞??у?虹?卞???扮?浠惰?峰?? 涓?????object绫诲??

??瀛??ㄦ???冲??浜????$??

GetParameter()锛??ユ?惰?锋????帮?

Session??缃?瀵硅薄浼???楠?璇?淇℃??

session瀵硅薄涓昏??ㄤ?淇?瀛??ㄦ?风????绉?淇℃?? ?ラ??瀹???澹版???ㄦ??锛?涓???900s锛?瓒??舵??琚?浜轰负???炬??

姣?涓??ㄦ?烽?芥??涓?涓? 涓????ㄤ?浼?楠?璇?淇℃??

渚?瀛?涓?

<%@ page contentType="text/html;charset=gb2312"%>
<%
	String flag = (String)session.getAttribute("flag") ;
	 
%>
<h1>flag : <%=flag%></h1>
<%if(flag!=null)
 out.print("杞?璐?????");
 else 
out.print("杞?璐?け璐?);%><br>
 
           

渚?瀛?浜?

<%@ page contentType="text/html;charset=gb2312"%>
<%
	String flag = (String)session.getAttribute("flag") ;
	 
    
%>
<h1>flag : <%=flag%></h1>
 <%if(flag!=null)
 out.print("??娆炬????");
 else 
out.print("??娆惧け璐?);%><br>
 <a href="sessionDemo03.jsp">杞?璐?lt;/a>
           

request.getRequestURI()

String currentURL = request.getRequestURI()

?垮??equest??璇锋?瀛?绗?覆

session??cookie

绗?涓?娆¤?块???讹????″?ㄤ???寤轰?涓??扮??sesion锛?骞朵???session??Id浠?ookie??褰㈠?????缁?瀹㈡?风??娴?瑙??? ?瑰?诲?锋?版????锛???娆¤?锋????″???姝ゆ?跺氨??浠ョ???版?瑙??ㄥ??璇锋????″?ㄦ?讹?浼???瀛??ㄥ??ookie涓???session??Id涓?璧蜂????版???″?ㄧ??浜?

session?????$??瀛????cookie??娴?瑙??ㄧ??瀛????涓?瀹????

Cookie?????ㄦ?风???版????缁??ㄦ?风??娴?瑙??ㄣ??

Session???????ㄦ?风???版?????扮?ㄦ?风??????session涓???

Session瀵硅薄?辨???″?ㄥ??寤猴?寮???浜哄????浠ヨ???equest瀵硅薄??getSession?规?寰???ession瀵硅薄

session.isNew()

?ㄧ?搴?涓?绗?涓?娆¤???equest.getSession()?规??跺氨浼???寤轰?涓??扮??Session锛???浠ョ??sNew()?规??ュ?ゆ??Session??涓????板??寤虹??

濡????惧?扮?稿??session??杩???false

浠?绯荤?cookie涓???session??

session.invalidate()浣?ession澶辨??

session.getattribute锛?锛?

application??缃?瀵硅薄浼??????变俊??

applicatio??servletContext???ュ?g被瀵硅薄

姝や俊???ㄦ?翠釜???″?ㄤ?琚?淇??? ?????ㄦ?烽?藉??浠ヤ?杩??????版?? ?诲?卞氨涓?涓?

<%
	String name = (String)application.getAttribute("name") ;
	String password = (String)application.getAttribute("password") ;
%>
<h1>name : <%=name%></h1>
<h1>password : <%=password%></h1>

           

application.getRealPath(??hello.jsp??)

?峰??缁?浠剁??缁?瀵硅矾寰?

page??缃?瀵硅薄瀛??句复?舵?版??

<%
	String name = (String)pageContext.getAttribute("name") ;
	String password = (String)pageContext.getAttribute("password") ;

%>
<h1>name : <%=name%></h1>
<h1>password : <%=password%></h1>
           

渚?瀛?浜?

<%
	pageContext.setAttribute("name","ZTE") ;
	pageContext.setAttribute("password","123") ;
%>
<%
	String name = (String)pageContext.getAttribute("name") ;
	String password = (String)pageContext.getAttribute("password") ;

%>
<h1>name : <%=name%></h1>
<h1>password : <%=password%></h1>
   <jsp:forward page="pageDemo02.jsp"/>  
           

pageContext瀵硅薄瀹???????缃?瀵硅薄灞??х??璁惧????

<%
	pageContext.setAttribute("name","tom",PageContext.APPLICATION_SCOPE) ;
	pageContext.setAttribute("password","345",PageContext.APPLICATION_SCOPE) ;
%>
<jsp:forward page="pageDemo04.jsp"/>
           

渚?瀛?浜?

<%
	String name = (String)application.getAttribute("name") ;
	String password = (String)application.getAttribute("password") ;
%>
<h1>name : <%=name%></h1>
<h1>password : <%=password%></h1>