有关JSP的几个内置对象——session/application/pageContext
2011-01-11 21:35
656 查看
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css" mce_href="styles.css"> --> </head> <body> <br> <%--if(u.equals("admin")) out.println(u); else out.println("error");--%> <% String u = request.getParameter("user"); out.println(u); %> <% if (pageContext.getAttribute("pageCount") == null) { pageContext.setAttribute("pageCount", new Integer(0)); } if (session.getAttribute("sessionCount") == null) { session.setAttribute("sessionCount", new Integer(0)); } if (application.getAttribute("appCount") == null) { application.setAttribute("appCount", new Integer(0)); } if (request.getAttribute("reqCount") == null) { request.setAttribute("reqCount", new Integer(0)); } %> <h1> session、application 和 pageContext </h1> <% Integer count = (Integer) pageContext.getAttribute("pageCount"); pageContext.setAttribute("pageCount", new Integer( count.intValue() + 1)); Integer count2 = (Integer) session.getAttribute("sessionCount"); session.setAttribute("sessionCount", new Integer( count2.intValue() + 1)); Integer count3 = (Integer) application.getAttribute("appCount"); application.setAttribute("appCount", new Integer( count3.intValue() + 1)); %> <b>页面计数= </b> <%=pageContext.getAttribute("pageCount")%> <br /> <b>会话计数= </b> <%=session.getAttribute("sessionCount")%> <br /> <b>应用程序计数= </b> <%=application.getAttribute("appCount")%> <br /> </body> </html>
运行结果:
pageContent的刷新一直为1
session的刷新增长,关掉并重新开起来一个浏览器后置1
application的刷新增长,关掉server后开起来置1
相关文章推荐
- JSP 内置对象(request response session application out pageContext)
- JSP内置对象之session application page pageContext config exception
- application、session、request、page 4个JSP内置对象详细介绍
- JSP内置对象:request, reponse, out, session, application, config, pagecontext, page, exception
- jsp九大内置对象:request、response、session、application、out、page、pageContext、config、exception
- JSP九大内置对象(Request,Response,Out,Session,Application,Cookie,Config,Page,Exception)
- JSP九大内置对象---Request,Response,Out,Session,Application,Cookie,Config,Page,Exception
- jsp内置对象out、request、response、session、application五大常用对象以及Page、pageContext、exception、config
- JSP内置对象--pageContent,request,response,session,application,config,out,page,exception
- page、request、session、application四个内置对象
- JSP内置对象之application、out、pageContext、config、page、exception
- jsp request、response、session、out、page、application、exception、pageContext、config对象详解
- 【JSP笔记】内置对象(二)session、application
- jsp和EL表达式 : pageContext.findAttribuate("") page域--->request--->session--->application
- java_web初学笔记之<Jsp四个域对象page/request/session/application>
- JSP内置对象application、out、page、config,exception总结(五)
- JSP内置对象之------response、session、application
- JSP内置对象详解3 之 session与application
- JSP基本功 pageContext对象page,request,session,application四个域对象的使用及区别JSP运行原理和九大隐式对象及下载文件、访问次数的代码总结出el表达式简单
- 浪潮优派培训笔记:JSP的9大内置对象之(一).与Servlet有关的内置对象: page、config