Page(pageContext)属性范围:
Public void setAttribute(String name,Object value,int scope)设置属性并指定保存范围
PAGE_SCOPE àpage属性范围 默认的
REQUEST_SCOPE àrequest属性范围 默认的
SESSION_SCOPE àsession属性范围 默认的
APPLICATION_SCOPE àapplication属性范围 默认的
<%pageContext. setAttribute (“name”,”jordan”,PageContext.REQUEST_SCOPE);%>
Request 使用最多的 接受客户端的信息
setCharacterEncoding()改变编码格式
response:
定时跳转:
response.setGeader(“refresh”,”0”,”URL=xxx.html”) 定时跳转
在html中也可使用 <META HTTP-EQUIV=”refresh”CONTENT=”3;URL=xxx.html”>
页面跳转:Response.sendRedirect(“xxx.html”); 客户端跳转 地址栏改变
跳转区别:在使用request属性范围时 只有是服务器跳转才能将request的属性保存到跳转页,服务器跳转直接跳转 客户端跳转在整个页面都执行完之后才跳转
如使用<jsp:forward>方便<jsp:param>传参
Cookie:
Cookie c1 = new Cookie(“name”,”Jordan”)//定义新的cookie
Cookie c2 = new Cookie(“id”,”23”)
C1.setMaxAge(60); //Cookie保存60秒
Response.addCookie(c1);//向客户端增加cookie
Response.addCookie(c2);
Cookie c[] = request.getCookies(); //取得全部的Cookie
for(int x = 0;x<c.length;x++;){
<%=c[x].getName()%>
<%=c[x].getValue()%>
}
Session 主要用于用户的登陆 注销等功能只能用用在HTTP协议中