JSP_<jsp:application>实例
2014-10-17 00:00
330 查看
本文出自:http://blog.csdn.net/svitter
实验环境:Myeclipse10 + tomcat7
Application对象为了多个应用程序保存信息,对于每个容器,每个用户都共同拥有一个application对象,服务器启动以后,会自动创建一个application对象,这个对象会一直保持到服务器关闭。
下列实例用于统计页面访问次数。
1.application.jsp
2.test_application.jsp
对应资源:
http://download.csdn.net/detail/svitter/7358563
实验环境:Myeclipse10 + tomcat7
Application对象为了多个应用程序保存信息,对于每个容器,每个用户都共同拥有一个application对象,服务器启动以后,会自动创建一个application对象,这个对象会一直保持到服务器关闭。
下列实例用于统计页面访问次数。
1.application.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <% int count = 0; String c_name = request.getParameter("c_name"); try { count = Integer.parseInt((application.getAttribute("c_name").toString())); } catch(Exception e){ } out.println("自服务器启动后,此页面已经被访问了" + count +"次"); count++; application.setAttribute("c_name", new Integer(count)); %>
2.test_application.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="utf-8" errorPage=""%> <% 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>使用计数器的例子</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <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"> --> </head> <body> 测试计数器<br> <jsp:include page="application.jsp"> <jsp:param name="c_name" value=" " /> </jsp:include> </body> </html>
对应资源:
http://download.csdn.net/detail/svitter/7358563
相关文章推荐
- JSP_<jsp:application>实例
- JSP入门<1>九大内置对象实例详解
- <JSP userBean>实例
- javaWeb入门<1>Servlet+Jsp+JavaBean实现MVC开发模式登陆注册实例详解
- JSP 30:<c:forEach/>的简单实例
- java_web初学笔记之<Jsp四个域对象page/request/session/application>
- Android实战简易教程<三十>(实例解析Application的用法)
- linux服务器配置实例<1>---Linux网络基础
- MyEclipse编写JSP,在<% %>中编写内容时卡死解决方法
- linux服务器配置实例<5>---配置Linux防火墙
- linux服务器配置实例<3>---配置DNS服务
- 大话西游之Office应用实例系列! <1>
- linux服务器配置实例<11>---配置邮件服务器
- 大话西游之Office应用实例系列! <2.5>
- 大话西游之Office应用实例系列! <2>
- 大话西游之Office应用实例系列! <6>
- 关于< tbody >的一个实例,很实用。
- 大话西游之Office应用实例系列! <8>
- 大话西游之Office应用实例系列! <5>