JSP _ (jsp: application) instance

Source: Internet
Author: User

 

Lab environment: Myeclipse10 + tomcat7

The Application object stores information for multiple applications. For each container, each user has an application object. After the server starts, an application object is automatically created, this object will be kept until the server is closed.

The following instances are used to count the page access times.

 

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 (after the server is started, This page has been accessed + count + times); 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+/;%>
> Test counter

Resources: http://download.csdn.net/detail/svitter/7358563

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.