⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplesession.jsp

📁 java的一系列产品中包括jsme,jmse,j2ee,本文件提供j2ee实现的源代码.
💻 JSP
字号:
<!-- Copyright (c) 1999-2002 by BEA Systems, Inc. All Rights Reserved.-->

<!-- Here we use a Java string ("PAGETITLE") to set 
     the same phrase as the title and as a head.-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=iso-8859-1">
<meta name="description" content="BEA WebLogic Server">

<meta name="keywords" content="BEA WebLogic Server">

<title>Simple Session</title>

<LINK REL="stylesheet" 
TYPE="text/css" 
HREF="wls_examples.css" 
TITLE="BEA WebLogic Server">


</head>

<body bgcolor="#ffffff" link="#3366cc" vlink="#9999cc" alink="#0000cc">

<!-- top intro paragraph tables -->
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0"  border="0" width="100%">
    <tr>
     <td  width="100%" bgcolor="#ff0000" height="1">
     <p class="small">&nbsp;</p>
     </td>
     </tr>
</table>

<table border=0 cellspacing="18" cellpadding="0">
<tr>
<td valign="top">
<a HREF="http://www.bea.com"><IMG SRC="images/logo_tm_onwt.jpg" alt="BEA Logo" border="0"></a>

 <h3>Simple Session</h3>
 
 </td>
 </tr>
</table>


<%@ page import="
import javax.naming.Context;
import javax.naming.InitialContext;
import weblogic.management.MBeanHome;
" %>
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0"  border="0" width="100%">
    <tr>
     <td  width="100%" bgcolor="#ff0000" height="1">
     <p class="small">&nbsp;</p>
     </td>
     </tr>
</table>

<table border=0 cellspacing="18" cellpadding="0">
<tr>
<td valign="top">
<p>
This JSP shows simple principles of session management
by incrementing a counter each time a user accesses a page.

<p>

<%!
  private int totalHits = 0;
  String serverName;
  String failoverMessage="";

  private String getServerName() {

    String toReturn = null;
    try {
        Context myCtx = new InitialContext();
	MBeanHome mbeanHome = (MBeanHome)myCtx.lookup("weblogic.management.home.localhome");
	toReturn=mbeanHome.getMBeanServer().getServerName();
      if (toReturn == null) {
        return "";
      } else {
        return toReturn;
      }
    }
    catch (Exception e) {
      return "";
    }
  }
%>

<%
  session = request.getSession(true);

  Integer ival = (Integer)session.getAttribute("simplesession.counter");
  if (ival == null) 
    ival = new Integer(1);
  else 
    ival = new Integer(ival.intValue() + 1);
  session.setAttribute("simplesession.counter", ival);
%>

<%
	serverName = getServerName();
	String s = (String) session.getAttribute("simplesession.servername");
	
	if (s != null)
		if (s.equals(serverName)) {
         failoverMessage = "";
	} else {
			failoverMessage = "(failing over from server" + s + ")";
		}

	session.setAttribute("simplesession.servername", serverName);

%>

<%
  Integer cnt = (Integer)application.getAttribute("simplesession.hitcount");
  if (cnt == null)
    cnt = new Integer(1);
  else
    cnt = new Integer(cnt.intValue() + 1);
  application.setAttribute("simplesession.hitcount", cnt);
%>

<table border=1 cellpadding=6>
<tr><td width=100% valign=top>
The server currently hosting this session is <B><%= serverName %><B><%= failoverMessage %>
</td>
</tr>
<tr><td width=50% valign=top>
<font face="Helvetica">
<h3>
You have hit this page <font color=red> <%= ival %></font> time<%= (ival.intValue() == 1) ? "" : "s" %>, <br>before the session times out.
</h3>
The value in <font color=red><b>red</b></font> is stored in the HTTP session (<font face="Courier New" size=-1>javax.servlet.http.HttpSession</font>), in an object named <font face="Courier New" size=-1>simplesession.counter</font>. This object has <i>session</i> scope and its integer value is re-set to <font color=red><b>1</b></font> when you reload the page after the session has timed out.
<p>
You can change the time interval after which a session times out. For more information, see the <a href= http://e-docs.bea.com/wls/docs70/webapp/sessions.html#session-timeout>Session Timeout</a> section under <a href= http://e-docs.bea.com/wls/docs70/webapp/sessions.html>Using Sessions And Session Persistence in Web Applications</a>.
</font></td>

<td width=50% valign=top><font face="Helvetica">
<h3>You have hit this page a total of <font color=green> <%= cnt %></font> time<%= (cnt.intValue() == 1) ? "" : "s" %>!
</h3>	

The value in <font color=green><b>green</b></font> is stored in the
Servlet Context (<font face="Courier New" size=-1>javax.servlet.ServletContext)</font>, in an object named <font face="Courier New" size=-1>simplesession.hitcount</font>. This object
has <i>application</i> scope and its integer value is incremented each time you
reload the page.

</font>
</td>
</tr></table>

 </td>
 </tr>
</table>
<br>
<!-- RED LINE -->
<table cellspacing="0" cellpadding="0"  border="0" width="100%">
    <tr>
     <td  width="100%" bgcolor="#ff0000" height="1">
     <p class="small">&nbsp;</p>
     </td>
     </tr>
</table>

<!-- FOOTER -->
<table cellspacing="0" cellpadding="0" border="0" width="100%">
  <tr>
    <td align="left">
      <p class="copyright">Last updated: March 2002</p>
    </td>
  </tr>
</table>

<table cellspacing="0" cellpadding="0" border="0" width="100%"><!-- RED LINE -->
   <tr> 
    <td  width="100%" bgcolor="#ff0000" height="1">
    <p class="small">&nbsp;</p>
    </td>
    </tr>
</table> 


 <p class="copyright"><a href="http://www.bea.com">Home</a> | 
        <a href="http://www.bea.com/about/index.html" target="_top">Corporate Info</a> | 
        <a href="http://www.bea.com/press/index.html" target="_top">News</a> | 
        <a href="http://www.bea.com/solutions/index.html" target="_top">Solutions</a> | 
        <a href="http://www.bea.com/products/index.html" target="_top">Products</a> | 
        <a href="http://www.bea.com/partners/index.html" target="_top">Partners</a> | 
        <a href="http://www.bea.com/services.html" target="_top">Services</a> | 
        <a href="http://www.bea.com/events/index.html" target="_top">Events</a> | 
        <a href="http://www.bea.com/download.html" target="_top">Download</a> | 
        <a href="http://www.bea.com/purchase.html" target="_top">How to Buy</a>
        <br>Copyright 2002, BEA Systems, Inc. All rights reserved. 
        <br>Required browser: Netscape 4.0 or higher, or Microsoft Internet Explorer 4.0 or higher.
        <br> <a href="http://www.bea.com/contact/index.html" target="_top">Contact BEA</a> 
      </p>

</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -