??xml version="1.0" encoding="utf-8" standalone="yes"?>jzzjzzjzz亚洲成熟少妇,精品久久久久久最新网址,日韩大胆人体http://www.aygfsteel.com/wadise/category/5981.htmlzh-cnFri, 02 Mar 2007 03:36:16 GMTFri, 02 Mar 2007 03:36:16 GMT60DAOhttp://www.aygfsteel.com/wadise/archive/2006/06/05/50607.htmlwadisewadiseMon, 05 Jun 2006 15:10:00 GMThttp://www.aygfsteel.com/wadise/archive/2006/06/05/50607.htmlhttp://www.aygfsteel.com/wadise/comments/50607.htmlhttp://www.aygfsteel.com/wadise/archive/2006/06/05/50607.html#Feedback0http://www.aygfsteel.com/wadise/comments/commentRss/50607.htmlhttp://www.aygfsteel.com/wadise/services/trackbacks/50607.html1.pȝ中所有数据库讉K都通过DAO来包?br />2.每个DAO实例代表一个原生的领域对象或实体。如果一个领域对象有一个独立的生命周期Q那么它应该有自qDAO?br />3.DAO代表在领域对象上的CURD操作?br />4.DAO允许ZCriteria的查询不同于用主键查询。我比较們֐构造一个finderҎ。该finderҎ的返回值是一个领域对象组的Collection集合
5.DAO不代表处理事务,Sessions或连接。这些在DAO外处理将更加灉|?br />
例子Q?br />GenericDao是CRUD操作的DAO基类?br />
public interface GenericDao <T, PK extends Serializable> {

    
/** Persist the newInstance object into database */
    PK create(T newInstance);

    
/** Retrieve an object that was previously persisted to the database using
     *   the indicated id as primary key
     
*/
    T read(PK id);

    
/** Save changes made to a persistent object.  */
    
void update(T transientObject);

    
/** Remove an object from persistent storage in the database */
    
void delete(T persistentObject);
}


下面是它的实现类Q?br />
public class GenericDaoHibernateImpl <T, PK extends Serializable>
    
implements GenericDao<T, PK>, FinderExecutor {
    
private Class<T> type;

    
public GenericDaoHibernateImpl(Class<T> type) {
        
this.type = type;
    }

    
public PK create(T o) {
        
return (PK) getSession().save(o);
    }

    
public T read(PK id) {
        
return (T) getSession().get(type, id);
    }

    
public void update(T o) {
        getSession().update(o);
    }

    
public void delete(T o) {
        getSession().delete(o);
    }
}


扩展GenericDAO
public interface PersonDao extends GenericDao<Person, Long> {
    List
<Person> findByName(String name);
}



wadise 2006-06-05 23:10 发表评论
]]>
Map的简易写?/title><link>http://www.aygfsteel.com/wadise/archive/2006/06/05/50598.html</link><dc:creator>wadise</dc:creator><author>wadise</author><pubDate>Mon, 05 Jun 2006 14:29:00 GMT</pubDate><guid>http://www.aygfsteel.com/wadise/archive/2006/06/05/50598.html</guid><wfw:comment>http://www.aygfsteel.com/wadise/comments/50598.html</wfw:comment><comments>http://www.aygfsteel.com/wadise/archive/2006/06/05/50598.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wadise/comments/commentRss/50598.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wadise/services/trackbacks/50598.html</trackback:ping><description><![CDATA[通常我们在初始化一个Map的时候,都要q样子:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Map test </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashMap();<br />test.put(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />test.put(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">22</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);</span></div><br />q样显得有点太J烦Q不像动态语a那么灉|。。但是我们可以这样写Q?br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 0);">Map test </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> </span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);"> HashMap() {<br />  {<br />    put(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">11</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />    put(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">, </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">22</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />   }<br />};</span></div><br />Collection同理!<br /><img src ="http://www.aygfsteel.com/wadise/aggbug/50598.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wadise/" target="_blank">wadise</a> 2006-06-05 22:29 <a href="http://www.aygfsteel.com/wadise/archive/2006/06/05/50598.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HttpSession二(转蝲Q?/title><link>http://www.aygfsteel.com/wadise/archive/2006/05/09/45274.html</link><dc:creator>wadise</dc:creator><author>wadise</author><pubDate>Tue, 09 May 2006 12:27:00 GMT</pubDate><guid>http://www.aygfsteel.com/wadise/archive/2006/05/09/45274.html</guid><wfw:comment>http://www.aygfsteel.com/wadise/comments/45274.html</wfw:comment><comments>http://www.aygfsteel.com/wadise/archive/2006/05/09/45274.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wadise/comments/commentRss/45274.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wadise/services/trackbacks/45274.html</trackback:ping><description><![CDATA[原文Qhttp://e-docs.bea.com/wls/docs70/webapp/sessions.html#100770<br /><br />Using Sessions and Session Persistence in Web Applications<a name="deploy-webapp"></a><p><a name="100367"></a>The following sections describe how to set up sessions and session persistence:</p><ul type="square"><p><a name="104397"></a></p><li type="square"><a >Overview of HTTP Sessions</a><p><a name="139644"></a></p></li><li type="square"><a >Setting Up Session Management</a><p><a name="104409"></a></p></li><li type="square"><a >Configuring Session Persistence</a><p><a name="104414"></a></p></li><li type="square"><a >Using URL Rewriting</a></li></ul><p> </p><hr noshade="noshade" /><p class="head1"><a name="139518"></a>Overview of HTTP Sessions</p><p><a name="139531"></a>Session tracking enables you to track a user's progress over multiple servlets or HTML pages, which, by nature, are stateless. A session is defined as a series of related browser requests that come from the same client during a certain time period. Session tracking ties together a series of browser requests—think of these requests as pages—that may have some meaning as a whole, such as a shopping cart application.</p><p> </p><hr noshade="noshade" /><p class="head1"><a name="100659"></a>Setting Up Session Management <a name="session-management"></a></p><p><a name="100660"></a>WebLogic Server is set up to handle session tracking by default. You need not set any of these properties to use session tracking. However, configuring how WebLogic Server manages sessions is a key part of tuning your application for best performance. Tuning depends upon factors such as: </p><ul type="square"><p><a name="100661"></a></p><li type="square">How many users you expect to hit the servlet <p><a name="100662"></a></p></li><li type="square">How many concurrent users hit the servlet <p><a name="100663"></a></p></li><li type="square">How long each session lasts <p><a name="100664"></a></p></li><li type="square">How much data you expect to store for each user <p><a name="139890"></a></p></li><li type="square">Heap size allocated to the WebLogic Server instance. </li></ul><p class="head2"><a name="100665"></a>HTTP Session Properties<a name="session-props"></a></p><p><a name="100666"></a>You configure WebLogic Server session tracking with properties in the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font>. For instructions on editing the WebLogic-specific deployment descriptor, see <a >Step 4: Define session parameters</a>.</p><p><a name="100675"></a>For a complete list of session attributes, see <a >jsp-descriptor</a>.</p><p><a name="141907"></a>WebLogic Server 7.0 introduced a change to the SessionID format that caused some load balancers to lose the ability to retain session stickiness. </p><p><a name="141908"></a>A new server startup flag, -Dweblogic.servlet.useExtendedSessionFormat=true , retains the information that the load-balancing application needs for session stickiness. The extended session ID format will be part of the URL if URL rewriting is activated, and the startup flag is set to true.</p><p class="head2"><a name="108118"></a>Session Timeout<a name="session-timeout"></a></p><p><a name="108122"></a>You can specify an interval of time after which HTTP sessions expire. When a session expires, all data stored in the session is discarded. You can set the interval in either web.xml or weblogic.xml:</p><ul type="square"><p><a name="108125"></a></p><li type="square">Set the <font class="code">TimeoutSecs</font> attribute in the<a >jsp-descriptor</a> of the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml.</font> This value is set in seconds. <p><a name="108223"></a></p></li><li type="square">Set the <session-timeout>(see <a >session-config</a><font class="code">)</font><font class="code">element</font> in the Web Application deployment descriptor, <font class="code">web.xml</font>. </li></ul><p class="head2"><a name="100676"></a>Configuring Session Cookies<a name="session-cookie"></a></p><p><a name="100677"></a>WebLogic Server uses cookies for session management when supported by the client browser. </p><p><a name="100678"></a>The cookies that WebLogic Server uses to track sessions are set as transient by default and do not outlive the session. When a user quits the browser, the cookies are lost and the session lifetime is regarded as over. This behavior is in the spirit of session usage and it is recommended that you use sessions in this way. </p><p><a name="109568"></a>You can configure session-tracking attributes of cookies in the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font>. A complete list of session and cookie-related attributes is available <a >jsp-descriptor</a>.</p><p><a name="109573"></a>For instructions on editing the WebLogic-specific deployment descriptor, see <a >Step 4: Define session parameters</a>.</p><p class="head2"><a name="100688"></a>Using Cookies<a name="long-cookie"></a> That Outlive a Session</p><p><a name="100689"></a>For longer-lived client-side user data, your application should create and set its own cookies on the browser via the HTTP servlet API, and should not attempt to use the cookies associated with the HTTP session. Your application might use cookies to auto-login a user from a particular machine, in which case you would set a new cookie to last for a long time. Remember that the cookie can only be sent from that client machine. Your application should store data on the server if it must be accessed by the user from multiple locations.</p><p><a name="100690"></a>You cannot directly connect the age of a browser cookie with the length of a session. If a cookie expires before its associated session, that session becomes orphaned. If a session expires before its associated cookie, the servlet is not be able to find a session. At that point, a new session is assigned when the <font class="code">request.getSession(true)</font> method is called. You should only make transient use of sessions.</p><p><a name="139898"></a>You can set the maximum life of a cookie with the <font class="code">CookieMaxAgeSecs</font> parameter in the session descriptor of the <font class="code">weblogic.xml</font> deployment descriptor. For more information, see <a >Step 4: Define session parameters</a></p><p class="head2"><a name="139365"></a>Logging Out and Ending a Session</p><p><a name="139397"></a>User authentication information is stored both in the user's session data and in the context of a server or virtual host that is targeted by a Web Application. The <font class="code">session.invalidate()</font> method, which is often used to log out a user, only invalidates the current session for a user—the user's authentication information still remains valid and is stored in the context of the server or virtual host. If the server or virtual host is hosting only one Web Application, the <font class="code">session.invalidate() </font>method, in effect, logs out the user. </p><p><a name="139398"></a>There are several Java methods and strategies you can use when using authentication with multiple Web Applications. For more information, see <a >Implementing Single Sign-On</a> in the <em>Programming WebLogic HTTP Servlets</em>,.</p><p> </p><hr noshade="noshade" /><p class="head1"><a name="139726"></a>Configuring Session Persistence<a name="session-persistence"></a></p><p><a name="140566"></a>Use Session Persistence to permanently stored data from an HTTP session object in order to enable failover and load balancing across a cluster of WebLogic Servers. When your applications stores data in an HTTP session object, the data must be serializable.</p><p><a name="139753"></a>There are five different implementations of session persistence: </p><ul type="square"><p><a name="100694"></a></p><li type="square">Memory (single-server, non-replicated) <p><a name="100695"></a></p></li><li type="square">File system persistence <p><a name="100696"></a></p></li><li type="square">JDBC persistence <p><a name="138904"></a></p></li><li type="square">Cookie-based session persistence <p><a name="100697"></a></p></li><li type="square">In-memory replication (across a cluster) </li></ul><p><a name="100699"></a>The first four are discussed here; in-memory replication is discussed in <a HTTP Session State Replication,"</a> in <em>Using WebLogic Server Clusters</em>. </p><p><a name="100700"></a>File, JDBC, Cookie-based, and memory (single-server, non-populated) session persistence have some common properties. Each persistence method has its own set of attributes, as discussed in the following sections.</p><p class="head2"><a name="100701"></a>Common Properties of Session Attributes<a name="common-props"></a></p><p><a name="100702"></a>This section describes attributes common to file system, memory (single-server, non-replicated), JDBC, and cookie-based persistence. You can configure the number of sessions that are held in memory by setting the following properties in the <font class="code"><session-descriptor></font> element of the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font>. These properties are only applicable if you are using session persistence: </p><dl><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100706"></a><strong><font class="code">CacheSize</font></strong></dd></font></p><dl><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100707"></a>Limits the number of cached sessions that can be active in memory at any one time. If you are expecting high volumes of simultaneous active sessions, you do not want these sessions to soak up the RAM of your server since this may cause performance problems swapping to and from virtual memory. When the cache is full, the least recently used sessions are stored in the persistent store and recalled automatically when required. If you do not use persistence, this property is ignored, and there is no soft limit to the number of sessions allowed in main memory. By default, the number of cached sessions is 1024. The minimum is 16, and maximum is <em><font class="code">Integer.MAX_VALUE</font></em>. An empty session uses less than 100 bytes, but grows as data is added to it. </dd></font></p></dl><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100708"></a><strong><font class="code">SwapIntervalSecs</font></strong></dd></font></p><dl><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100709"></a>The interval the server waits between purging the least recently used sessions from the cache to the persistent store, when the <font class="code">cacheEntries</font> limit has been reached. </dd></font></p><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100710"></a>If unset, this property defaults to 10 seconds; minimum is 1 second, and maximum is 604800 (1 week). </dd></font></p></dl><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100711"></a><strong><font class="code">InvalidationIntervalSecs</font></strong></dd></font></p><dl><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="107731"></a>Sets the time, in seconds, that WebLogic Server waits between doing house-cleaning checks for timed-out and invalid sessions, and deleting the old sessions and freeing up memory. Set this parameter to a value less than the value set for the <font class="code"><session-timeout></font> element. Use this parameter to tune WebLogic Server for best performance on high traffic sites.</dd></font></p><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="100713"></a>The minimum value is every second (1). The maximum value is once a week (604,800 seconds). If unset, the parameter defaults to 60 seconds.</dd></font></p><p><font color="#000000" face="Verdana,Geneva,Arial,Helvetica,sans-serif" size="-1"><dd><a name="109632"></a>To set <font class="code"><session-timeout>, see</font> the <a >session-config</a> of the Web Application deployment descriptor <font class="code">web.xml</font>. </dd></font></p></dl></dl><p class="head2"><a name="100714"></a>Using Memory-based, Single-server, Non-replicated Persistent Storage<a name="memoy-persistence"></a></p><p><a name="100715"></a>To use memory-based, single-server, non-replicated persistent storage, set the <font class="code">PersistentStoreType</font> property in the <font class="code"><session-descriptor></font> element of the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font> to <font class="code">memory.</font> When you use memory-based storage, all session information is stored in memory and is lost when you stop and restart WebLogic Server.</p><p><a name="139953"></a><strong>Note: </strong> If you do not allocate sufficient heap size when running WebLogic Server, your server may run out of memory under heavy load.</p><p class="head2"><a name="100716"></a>Using File-based Persistent Storage <a name="file_persistence"></a></p><p><a name="100717"></a>To configure file-based persistent storage for sessions: </p><ol type="1"><li value="1"><a name="100718"></a>Set the <font class="code">PersistentStoreType</font> property in the <font class="code"><session-descriptor></font> element in the deployment descriptor file <font class="code">weblogic.xml</font> to <font class="code">file</font>. </li><li value="2"><a name="107755"></a>Set the directory where WebLogic Server stores the sessions. See <a >PersistentStoreDir</a>. <p><a name="107859"></a> If you do not explicitly set a value for this attribute, a temporary directory is created for you by WebLogic Server. </p><p><a name="113930"></a> If you are using file-based persistence in a cluster, you must explicitly set this attribute to a shared directory that is accessible to all the servers in a cluster. You must create this directory yourself.</p></li></ol><p class="head2"><a name="113932"></a>Using a Database for Persistent <a name="jdbc_persistence"></a>Storage (JDBC persistence)</p><p><a name="139756"></a>JDBC persistence stores session data in a database table using a schema provided for this purpose. You can use any database for which you have a JDBC driver. You configure database access by using connection pools.</p><p><a name="113933"></a>To configure JDBC-based persistent storage for sessions: </p><ol type="1"><li value="1"><a name="100724"></a>Set the <font class="code">PersistentStoreType</font> property in the <font class="code"><session-descriptor></font> element of the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font>, to <font class="code">jdbc.</font></li><li value="2"><a name="100725"></a>Set a JDBC connection pool to be used for persistence storage with the <font class="code">PersistentStorePool</font> property of the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font>. Use the name of a connection pool that is defined in the WebLogic Server Administration Console. <dl><dt></dt><p class="listpara"><a name="100731"></a>For more details on setting up a database connection pool, see <a >Managing JDBC Connectivity</a>.</p></dl></li><li value="3"><a name="100733"></a>Set an ACL for the connection that corresponds to the users that have permission. For more details on setting up a database connection, see <a >Managing JDBC Connectivity</a>. </li><li value="4"><a name="140305"></a>Set up a database table named <font class="code">wl_servlet_sessions</font> for JDBC-based persistence. The connection pool that connects to the database needs to have read/write access for this table. The following table shows the Column names and data types you should use when creating this table.</li></ol><p><a name="140384"></a><strong><div id="wmqeeuq" class="tblmargin"><table bordercolorlight="#FFFFFF" bordercolordark="#000000" border="1" cellpadding="3" cellspacing="0"><tbody><tr bgcolor="#cccccc"><th align="left" valign="top"><b><p class="table"><a name="140388"></a><strong>Column name</strong></p></b></th><th align="left" valign="top"><b><p class="table"><a name="140390"></a><strong>Type</strong></p></b></th></tr><tr><td align="left" valign="top"><p class="table"><a name="140392"></a><font class="code">wl_id</font></p></td><td align="left" valign="top"><p class="table"><a name="140394"></a> Variable-width alphanumeric column, up to 100 characters; for example, Oracle <font class="code">VARCHAR2(100)</font>.<br /><em> The primary key must be set as follows:</em></p><p class="table"><a name="140395"></a><font class="code">wl_id + wl_context_path.</font></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140397"></a><font class="code">wl_context_path</font></p></td><td align="left" valign="top"><p class="table"><a name="140399"></a>Variable-width alphanumeric column, up to 100 characters; for example, Oracle <font class="code">VARCHAR2(100)</font>. <em>This column is used as part of the primary key. (See the </em><font class="code">wl_id</font><em>column</em><em> description.)</em></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140401"></a><font class="code">wl_is_new</font></p></td><td align="left" valign="top"><p class="table"><a name="140403"></a>Single char column; for example, Oracle <font class="code">CHAR(1)</font></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140405"></a><font class="code">wl_create_time</font></p></td><td align="left" valign="top"><p class="table"><a name="140407"></a>Numeric column, 20 digits; for example, Oracle <font class="code">NUMBER(20)</font></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140409"></a><font class="code">wl_is_valid</font></p></td><td align="left" valign="top"><p class="table"><a name="140411"></a>Single char column; for example, Oracle <font class="code">CHAR(1)</font></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140413"></a><font class="code">wl_session_values</font></p></td><td align="left" valign="top"><p class="table"><a name="140415"></a>Large binary column; for example, Oracle <font class="code">LONG RAW</font></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140417"></a><font class="code">wl_access_time</font></p></td><td align="left" valign="top"><p class="table"><a name="140419"></a>Numeric column, 20 digits; for example, <font class="code">NUMBER(20)</font></p></td></tr><tr><td align="left" valign="top"><p class="table"><a name="140421"></a><font class="code">wl_max_inactive_interval</font></p></td><td align="left" valign="top"><p class="table"><a name="140423"></a>Integer column; for example, Oracle <font class="code">Integer</font>. Number of seconds between client requests before the session is invalidated. A negative time value indicates that the session should never timeout.</p></td></tr></tbody></table></div></strong></p><p><a name="140345"></a>If you are using an Oracle DBMS, use the following SQL statement to create the <font class="code">wl_servlet_sessions</font> table:</p><blockquote><pre><font color="#000000" face="Courier"><a name="119416"></a>create table wl_servlet_sessions<br /> ( wl_id VARCHAR2(100) NOT NULL,<br /> wl_context_path VARCHAR2(100) NOT NULL,<br /> wl_is_new CHAR(1),<br /> wl_create_time NUMBER(20),<br /> wl_is_valid CHAR(1),<br /> wl_session_values LONG RAW,<br /> wl_access_time NUMBER(20),<br /> wl_max_inactive_interval INTEGER,<br /> PRIMARY KEY (wl_id, wl_context_path) ); <br /></font></pre></blockquote><p><a name="141957"></a>If you are using SqlServer2000, use the following SQL statement to create the <font class="code">wl_servlet_sessions</font> table:</p><blockquote><pre><font color="#000000" face="Courier"><a name="141958"></a>create table wl_servlet_sessions<br /> ( wl_id VARCHAR2(100) NOT NULL,<br /> wl_context_path VARCHAR2(100) NOT NULL,<br /> wl_is_new VARCHAR(1),<br /> wl_create_time DeCIMAL,<br /> wl_is_valid VARCHAR(1),<br /> wl_session_values IMAGE,<br /> wl_access_time DECIMAL,<br /> wl_max_inactive_interval INTEGER,<br /> PRIMARY KEY (wl_id, wl_context_path) ); <br /></font></pre></blockquote><p><a name="119429"></a>Modify one of the preceeding SQL statements for use with your DBMS.</p><p><a name="119417"></a><strong>Note: </strong> You can configure a maximum duration that JDBC session persistence should wait for a JDBC connection from the connection pool before failing to load the session data with the <font class="code">JDBCConnectionTimeoutSecs</font> attribute. For more information, see <a >JDBCConnectionTimeoutSecs</a>.</p><p class="head2"><a name="138913"></a>Using Cookie-Based Session Persistence</p><p><a name="138914"></a>Cookie-based session persistence provides a stateless solution for session persistence by storing all session data in a cookie that is stored in the user's browser. Cookie-based session persistence is most useful when you do not need to store large amounts of data in the session. Cookie-based session persistence can make managing your WebLogic Server installation easier because clustering failover logic is not required. Because the session is stored in the browser, not on the server, you can start and stop WebLogic Servers without losing sessions.</p><p><a name="138928"></a>There are some limitations to cookie-based session persistence:</p><ul type="square"><p><a name="138949"></a></p><li type="square">You can store only string attributes in the session. If you store any other type of object in the session, an <font class="code">IllegalArgument</font> exception is thrown. <p><a name="138968"></a></p></li><li type="square">You cannot flush the HTTP response (because the cookie must be written to the header data <em>before</em> the response is committed). <p><a name="139155"></a></p></li><li type="square">If the content length of the response exceeds the buffer size, the response is automatically flushed and the session data cannot be updated in the cookie. (The buffer size is, by default, 8192 bytes. You can change the buffer size with the <font class="code">javax.servlet.ServletResponse.setBufferSize()</font> method. <p><a name="138985"></a></p></li><li type="square">You can only use basic (browser-based) authentication. <p><a name="139186"></a></p></li><li type="square">Session data is sent to the browser in clear text. <p><a name="139191"></a></p></li><li type="square">The user's browser must be configured to accept cookies. <p><a name="141838"></a></p></li><li type="square">You cannot use commas (,) in a string when using cookie-based session persistence or an exception occurs. </li></ul><p><a name="138990"></a>To set up cookie-based session persistence:</p><ol type="1"><li value="1"><a name="139001"></a>In the <font class="code"><session-descriptor></font> element of <font class="code">weblogic.xml</font>, set the <font class="code">PersistentStoreType</font> parameter to <font class="code">cookie.</font></li><li value="2"><a name="139037"></a>Optionally, set a name for the cookie using the <font class="code">PersistentStoreCookieName</font> parameter. The default is <font class="code">WLCOOKIE</font>.</li></ol><p> </p><hr noshade="noshade" /><p class="head1"><a name="100770"></a><a name="urlrewriting"></a>Using URL Rewriting<a name="url-rewriting"></a></p><p><a name="100771"></a>In some situations, a browser or wireless device may not accept cookies, which makes session tracking using cookies impossible. URL rewriting is a solution to this situation that can be substituted automatically when WebLogic Server detects that the browser does not accept cookies. URL rewriting involves encoding the session ID into the hyper-links on the Web pages that your servlet sends back to the browser. When the user subsequently clicks these links, WebLogic Server extracts the ID from the URL address and finds the appropriate <font class="code">HttpSession</font> when your servlet calls the <font class="code">getSession()</font> method. </p><p><a name="100773"></a>Enable URL rewriting in WebLogic Server by setting the <font class="code">URLRewritingEnabled</font> attribute in the WebLogic-specific deployment descriptor, <font class="code">weblogic.xml</font>, under the <font class="code"><session-descriptor></font> element.<font class="code"></font>The default value for this attribute is <font class="code">true</font>. See <a >URLRewritingEnabled</a>. </p><p class="head2"><a name="100777"></a>Coding Guidelines for URL Rewriting</p><p><a name="123231"></a>There are some general guidelines for how your code should handle URLs in order to support URL rewriting. </p><ul type="square"><p><a name="123247"></a></p><li type="square">Avoid writing a URL straight to the output stream, as shown here: <blockquote><pre><font color="#000000" face="Courier"><a name="100778"></a>out.println("<a href=\"/myshop/catalog.jsp\">catalog</a>");</font></pre></blockquote><dl><dt></dt><p class="listpara"><a name="100779"></a>Instead, use the <font class="code">HttpServletResponse.encodeURL()</font> method, for example:</p><blockquote><pre><font color="#000000" face="Courier"><a name="100780"></a>out.println("<a href=\""<br /> + response.encodeURL("myshop/catalog.jsp") <br /> + "\">catalog</a>");</font></pre></blockquote><dt></dt><p class="listpara"><a name="100781"></a>Calling the <font class="code">encodeURL()</font> method determines if the URL needs to be rewritten, and if so, it rewrites it by including the session ID in the URL. The session ID is appended to the URL and begins with a semicolon.</p></dl><p><a name="100782"></a></p></li><li type="square">In addition to URLs that are returned as a response to WebLogic Server, also encode URLs that send redirects. For example: <blockquote><pre><font color="#000000" face="Courier"><a name="100783"></a>if (session.isNew())<br />  response.sendRedirect (response.encodeRedirectUrl(welcomeURL)); </font></pre></blockquote><dl><dt></dt><p class="listpara"><a name="100784"></a>WebLogic Server uses URL rewriting when a session is new, even if the browser does accept cookies, because the server cannot tell whether a browser accepts cookies in the first visit of a session. </p></dl><p><a name="109664"></a></p></li><li type="square">Your servlet can determine whether a given session ID was received from a cookie by checking the Boolean returned from the <font class="code">HttpServletRequest.isRequestedSessionIdFromCookie()</font> method. Your application may respond appropriately, or simply rely on URL rewriting by WebLogic Server. </li></ul><p class="head2"><a name="109666"></a>URL Rewriting and Wireless Access Protocol (WAP) <a name="wap"></a></p><p><a name="139999"></a>If you are writing a WAP application, you must use URL rewriting because the WAP protocol does not support cookies. In addition, some WAP devices have a 128-character limit on the length of a URL (including parameters), which limits the amount of data that can be transmitted using URL rewriting. To allow more space for parameters, you can limit the size of the session ID that is randomly generated by WebLogic Server. See <a >IDLength</a>.</p><img src ="http://www.aygfsteel.com/wadise/aggbug/45274.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wadise/" target="_blank">wadise</a> 2006-05-09 20:27 <a href="http://www.aygfsteel.com/wadise/archive/2006/05/09/45274.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>HttpSession一Q{载)http://www.aygfsteel.com/wadise/archive/2006/05/09/45273.htmlwadisewadiseTue, 09 May 2006 12:26:00 GMThttp://www.aygfsteel.com/wadise/archive/2006/05/09/45273.htmlhttp://www.aygfsteel.com/wadise/comments/45273.htmlhttp://www.aygfsteel.com/wadise/archive/2006/05/09/45273.html#Feedback0http://www.aygfsteel.com/wadise/comments/commentRss/45273.htmlhttp://www.aygfsteel.com/wadise/services/trackbacks/45273.html
摘要Q虽然session机制在web应用E序中被采用已经很长旉了,但是仍然有很多h不清楚session机制的本质,以至不能正确的应用这一技术? 本文详l讨论session的工作机制ƈ且对在Java web application中应用session机制时常见的问题作出解答?br />
目录Q?br />一、术语session
二、HTTP协议与状态保?br />三、理解cookie机制
四、理解session机制
五、理解javax.servlet.http.HttpSession
六、HttpSession常见问题
七、跨应用E序的session׃n
八、ȝ
参考文?br />
一、术语session
在我的经验里Qsessionq个词被滥用的程度大概仅ơ于transactionQ更加有的是transaction与session在某些语境下的含义是相同的?br />
sessionQ? 中文l常译Z话,其本来的含义是指有始有终的一pd动作/消息Q比如打电话时从拿v电话拨号到挂断电话这中间的一pdq程可以UCZ?  session。有时候我们可以看到这L话“在一个浏览器会话期间Q?..”,q里的会话一词用的就是其本义Q是指从一个浏览器H口打开到关闭这个期 闾b①。最混ؕ的是“用P客户端)在一ơ会话期间”这样一句话Q它可能指用L一pd动作Q一般情况下是同某个具体目的相关的一pd动作Q比如从d? 选购商品到结账登样一个网上购物的q程Q有时候也被称Z个transactionQ,然而有时候也可能仅仅是指一ơ连接,也有可能是指含义①,其中 的差别只能靠上下文来推断②?br />
然而当session一词与|络协议相关联时Q它又往往隐含了“面向连接”和/或“保持状态”这样两个含 义, “面向连接”指的是在通信双方在通信之前要先建立一个通信的渠道,比如打电话,直到Ҏ接了电话通信才能开始,与此相对的是写信Q在你把信发出去? 时候你q不能确认对方的地址是否正确Q通信渠道不一定能建立Q但对发信h来说Q通信已经开始了。“保持状态”则是指通信的一方能够把一pd的消息关联v 来,使得消息之间可以互相依赖Q比如一个服务员能够认出再次光的老顾客ƈ且记得上ơ这个顾客还Ơ店里一块钱。这一cȝ例子有“一? TCP session”或者 “一个POP3 session”③?br />
而到了web服务器蓬勃发展的时代Qsession在web开发语 境下的语义又有了新的扩展Q它的含义是指一cȝ来在客户端与服务器之间保持状态的解决Ҏ④。有时候session也用来指q种解决Ҏ的存储结构,? “把xxx保存在session 里”⑤。由于各U用于web开发的语言在一定程度上都提供了对这U解x案的支持Q所以在某种特定语言的语境下Q? session也被用来指代该语a的解x案,比如l常把Java里提供的javax.servlet.http.HttpSessionUCؓ session⑥?br />
鉴于q种混ؕ已不可改变,本文中session一词的q用也会Ҏ上下文有不同的含义,请大家注意分辨?br />在本文中Q用中文“浏览器会话期间”来表达含义①,使用“session机制”来表达含义④,使用“session”表辑֐义⑤Q用具体的“HttpSession”来表达含义?br />
二、HTTP协议与状态保?br />HTTP  协议本n是无状态的Q这与HTTP协议本来的目的是相符的,客户端只需要简单的向服务器h下蝲某些文gQ无论是客户端还是服务器都没有必要纪录彼此过? 的行为,每一ơ请求之间都是独立的Q好比一个顾客和一个自动售货机或者一个普通的Q非会员Ӟ大卖Z间的关系一栗?br />
然而聪明(或者贪 心?Q的Z很快发现如果能够提供一些按需生成的动态信息会使web变得更加有用Q就像给有线电视加上Ҏ功能一栗这U需求一斚wqHTML逐步d 了表单、脚本、DOM{客L行ؓQ另一斚w在服务器端则出现了CGI规范以响应客L的动态请求,作ؓ传输载体的HTTP协议也添加了文g上蝲?  cookieq些Ҏ。其中cookie的作用就是ؓ了解决HTTP协议无状态的~陷所作出的努力。至于后来出现的session机制则是又一U在客户 端与服务器之间保持状态的解决Ҏ?br />
让我们用几个例子来描qC下cookie和session机制之间的区别与联系。笔者曾l常ȝ一家咖啡店有喝5杯咖啡免费赠一杯咖啡的优惠Q然而一ơ性消?杯咖啡的Z微乎其微Q这时就需要某U方式来U录某位֮的消Ҏ量。想象一下其实也无外乎下面的几种ҎQ?br />1、该店的店员很厉宻I能记住每位顾客的消费数量Q只要顾客一走进咖啡店,店员q道该怎么对待了。这U做法就是协议本w支持状态?br />2、发l顾客一张卡片,上面记录着消费的数量,一般还有个有效期限。每ơ消ҎQ如果顾客出C张卡片,则此ơ消费就会与以前或以后的消费相联pv来。这U做法就是在客户端保持状态?br />3、发l顾客一张会员卡Q除了卡号之外什么信息也不纪录,每次消费Ӟ如果֮出示该卡片,则店员在店里的纪录本上找到这个卡号对应的U录d一些消费信息。这U做法就是在服务器端保持状态?br />
? 于HTTP协议是无状态的Q而出于种U考虑也不希望使之成ؓ有状态的Q因此,后面两种Ҏ成为现实的选择。具体来说cookie机制采用的是在客L? 持状态的ҎQ而session机制采用的是在服务器端保持状态的Ҏ。同时我们也看到Q由于采用服务器端保持状态的Ҏ在客L也需要保存一个标识,所 以session机制可能需要借助于cookie机制来达C存标识的目的Q但实际上它q有其他选择?br />
三、理解cookie机制 
cookie机制的基本原理就如上面的例子一L单,但是q有几个问题需要解冻I“会员卡”如何分发;“会员卡”的内容Q以及客户如何用“会员卡”?br />
正统的cookie分发是通过扩展HTTP协议来实现的Q服务器通过在HTTP的响应头中加上一行特D的指示以提C浏览器按照指示生成相应的cookie。然而纯_的客户端脚本如JavaScript或者VBScript也可以生成cookie?br />
而cookie  的用是由浏览器按照一定的原则在后台自动发送给服务器的。浏览器查所有存储的cookieQ如果某个cookie所声明的作用范围大于等于将要请求的 资源所在的位置Q则把该cookie附在h资源的HTTPh头上发送给服务器。意思是麦当劳的会员卡只能在麦当劳的店里出示Q如果某家分店还发行了自 q会员卡,那么q这家店的时候除了要出示麦当劳的会员卡,q要出示q家店的会员卡?br />
cookie的内容主要包括:名字Q|q期旉Q\径和域?br />其中域可以指定某一个域比如.google.comQ相当于d招牌Q比如宝z公司,也可以指定一个域下的具体某台机器比如www.google.com或者froogle.google.comQ可以用飘柔来做比?br />路径是跟在域名后面的URL路径Q比?或?foo{等Q可以用某飘柔专柜做比?br />路径与域合在一起就构成了cookie的作用范围?br />? 果不讄q期旉Q则表示q个cookie的生命期为浏览器会话期间Q只要关闭浏览器H口Qcookie消׃。这U生命期为浏览器会话期的  cookie被称Z话cookie。会话cookie一般不存储在硬盘上而是保存在内存里Q当然这U行为ƈ不是规范规定的。如果设|了q期旉Q浏? 器就会把cookie保存到硬盘上Q关闭后再次打开览器,q些cookie仍然有效直到过讑֮的过期时间?br />
存储在硬盘上? cookie 可以在不同的览器进E间׃nQ比如两个IEH口。而对于保存在内存里的cookieQ不同的览器有不同的处理方式。对于IEQ在一个打 开的窗口上按 Ctrl-NQ或者从文g菜单Q打开的窗口可以与原窗口共享,而用其他方式新开的IEq程则不能共享已l打开的窗口的内存cookieQ? 对于 Mozilla Firefox0.8Q所有的q程和标{N都可以共享同Lcookie。一般来说是用javascript? window.open打开的窗口会与原H口׃n内存cookie。浏览器对于会话cookie的这U只认cookie不认人的处理方式l常l采? session机制的web应用E序开发者造成很大的困扰?br />
下面是一个goolge讄cookie的响应头的例?br />HTTP/1.1 302 Found
Location: http://www.google.com/intl/zh-CN/
Set-Cookie: PREF=ID=0565f77e132de138:NW=1:TM=1098082649:LM=1098082649:S=KaeaCFPo49RiA_d8; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com
Content-Type: text/html




q是使用HTTPLookq个HTTP Sniffer软g来俘LHTTP通讯U录的一部分




览器在再次讉Kgoolge的资源时自动向外发送cookie




使用Firefox可以很容易的观察现有的cookie的?br />使用HTTPLook配合Firefox可以很容易的理解cookie的工作原理?br />



IE也可以设|在接受cookie前询?br />



q是一个询问接受cookie的对话框?br />
四、理解session机制
session机制是一U服务器端的机制Q服务器使用一U类g散列表的l构Q也可能是使用散列表)来保存信息?br />
? E序需要ؓ某个客户端的h创徏一个session的时候,服务器首先检查这个客L的请求里是否已包含了一个session标识 - UCؓ  session idQ如果已包含一个session id则说明以前已lؓ此客L创徏qsessionQ服务器按照session id把这?  session索出来用(如果索不刎ͼ可能会新Z个)Q如果客Lh不包含session idQ则为此客户端创Z个sessionq且? 成一个与此session相关联的session idQsession id的值应该是一个既不会重复Q又不容易被扑ֈ规律以仿造的字符Ԍq个  session id被在本ơ响应中q回l客L保存?br />
保存q个session id的方式可以采用cookieQ这样在交互q程? 览器可以自动的按照规则把这个标识发挥给服务器。一般这个cookie的名字都是类gSEEESIONIDQ而。比如weblogic对于web应用 E序生成的cookieQJSESSIONID=  ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764Q它的名字就?  JSESSIONID?br />
׃cookie可以被h为的止Q必L其他机制以便在cookie被禁止时仍然能够把session id 传递回服务器。经常被使用的一U技术叫做URL重写Q就是把session id直接附加在URL路径的后面,附加方式也有两种Q一U是作ؓURL路径? 附加信息Q表现Ş式ؓhttp://...../xxx;jsessionid= ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764
另一U是作ؓ查询字符串附加在URL后面Q表现Ş式ؓhttp://...../xxx?jsessionid=ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764
q两U方式对于用h说是没有区别的,只是服务器在解析的时候处理的方式不同Q采用第一U方式也有利于把session id的信息和正常E序参数区分开来?br />Z在整个交互过E中始终保持状态,必d每个客户端可能请求的路径后面都包含这个session id?br />
另一U技术叫做表单隐藏字Dc就是服务器会自动修改表单,d一个隐藏字D,以便在表单提交时能够把session id传递回服务器。比如下面的表单
<form name="testform" action="/xxx">
<input type="text">
</form>
在被传递给客户端之前将被改写成
<form name="testform" action="/xxx">
<input type="hidden" name="jsessionid" value="ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng!-145788764">
<input type="text">
</form>
q种技术现在已较少应用Q笔者接触过的很古老的iPlanet6(SunONE应用服务器的前n)׃用了q种技术?br />实际上这U技术可以简单的用对action应用URL重写来代ѝ?br />
? 谈论session机制的时候,常常听到q样一U误解“只要关闭浏览器Qsession消׃”。其实可以想象一下会员卡的例子,除非֮d对店家提 出销卡,否则店家l对不会L删除֮的资料。对session来说也是一LQ除非程序通知服务器删除一个sessionQ否则服务器会一直保留,E序 一般都是在用户做log off的时候发个指令去删除session。然而浏览器从来不会d在关闭之前通知服务器它要关闭Q因此服务器Ҏ不会有机? 知道览器已l关闭,之所以会有这U错觉,是大部分session机制都用会话cookie来保存session idQ而关闭浏览器后这?  session id消׃Q再ơ连接服务器时也无法找到原来的session。如果服务器讄的cookie被保存到盘上,或者用某U手D| 写浏览器发出的HTTPh_把原来的session id发送给服务器,则再ơ打开览器仍然能够找到原来的session?br />
恰恰是由于关闭浏览器不会Dsession被删除,q服务器ؓseesion讄了一个失效时_当距dL上一ơ用session的时间超q这个失效时间时Q服务器可以认为客L已经停止了活动,才会把session删除以节省存储空间?br />
五、理解javax.servlet.http.HttpSession
HttpSession是Javaq_对session机制的实现规范,因ؓ它仅仅是个接口,具体到每个web应用服务器的提供商,除了对规范支持之外,仍然会有一些规范里没有规定的细微差异。这里我们以BEA的Weblogic Server8.1作ؓ例子来演C?br />
? 先,Weblogic Server提供了一pd的参数来控制它的HttpSession的实玎ͼ包括使用cookie的开关选项Q用URL重写的开? 选项Qsession持久化的讄Qsession失效旉的设|,以及针对cookie的各U设|,比如讄cookie的名字、\径、域Q?  cookie的生存时间等?br />
一般情况下Qsession都是存储在内存里Q当服务器进E被停止或者重启的时候,内存里的session 也会被清I,如果讄了session的持久化Ҏ,服务器就会把session保存到硬盘上Q当服务器进E重新启动或q些信息能够被再次使用Q?  Weblogic Server支持的持久性方式包括文件、数据库、客Lcookie保存和复制?br />
复制严格说来不算持久化保存,因ؓsession实际上还是保存在内存里,不过同样的信息被复制到各个cluster内的服务器进E中Q这样即使某个服务器q程停止工作也仍然可以从其他q程中取得session?br />
cookie生存旉的设|则会媄响浏览器生成的cookie是否是一个会话cookie。默认是使用会话cookie。有兴趣的可以用它来试验我们在第四节里提到的那个误解?br />
cookie的\径对于web应用E序来说是一个非帔R要的选项QWeblogic Server对这个选项的默认处理方式得它与其他服务器有明昄区别。后面我们会专题讨论?br />
关于session的设|参考[5] http://e-docs.bea.com/wls/docs70/webapp/weblogic_xml.html#1036869

六、HttpSession常见问题
Q在本小节中session的含义ؓ⑤和⑥的混合Q?br />

1、session在何时被创徏
一 个常见的误解是以为session在有客户端访问时p创徏Q然而事实是直到某server端程序调?  HttpServletRequest.getSession(true)q样的语句时才被创徏Q注意如果JSP没有昄的用?lt;%  @page session="false"%> 关闭sessionQ则JSP文g在编译成Servlet时将会自动加上这样一条语?  HttpSession session = HttpServletRequest.getSession(true);q也是JSP中隐含的  session对象的来历?br />
׃session会消耗内存资源,因此Q如果不打算使用sessionQ应该在所有的JSP中关闭它?br />
2、session何时被删?br />l合前面的讨论,session在下列情况下被删除a.E序调用HttpSession.invalidate();或b.距离上一ơ收到客L发送的session id旉间隔过了session的超时设|?或c.服务器进E被停止Q非持久sessionQ?br />
3、如何做到在览器关闭时删除session
严格的讲Q做不到q一炏V可以做一点努力的办法是在所有的客户端页面里使用javascript代码window.oncolose来监视浏览器的关闭动作,然后向服务器发送一个请求来删除session。但是对于浏览器崩溃或者强行杀死进E这些非常规手段仍然无能为力?br />
4、有个HttpSessionListener是怎么回事
? 可以创徏q样的listenerȝ控session的创建和销毁事Ӟ使得在发生这L事g时你可以做一些相应的工作。注意是session的创建和销 毁动作触发listenerQ而不是相反。类似的与HttpSession有关的listenerq有  HttpSessionBindingListenerQHttpSessionActivationListener?  HttpSessionAttributeListener?br />
5、存攑֜session中的对象必须是可序列化的?br />不是必需 的。要求对象可序列化只是ؓ了session能够在集中被复制或者能够持久保存或者在必要时server能够暂时把session交换出内存。在  Weblogic Server的session中放|一个不可序列化的对象在控制C会收C个警告。我所用过的某个iPlanet版本如果  session中有不可序列化的对象Q在session销毁时会有一个ExceptionQ很奇怪?br />
6、如何才能正的应付客户端禁止cookie的可能?br />Ҏ有的URL使用URL重写Q包括超链接Qform的actionQ和重定向的URLQ具体做法参见[6]
http://e-docs.bea.com/wls/docs70/webapp/sessions.html#100770

7、开两个览器窗口访问应用程序会使用同一个sessionq是不同的session
参见W三节对cookie的讨论,对session来说是只认id不认人,因此不同的浏览器Q不同的H口打开方式以及不同的cookie存储方式都会对这个问题的{案有媄响?br />
8、如何防止用h开两个览器窗口操作导致的session混ؕ
q? 个问题与防止表单多次提交是类似的Q可以通过讄客户端的令牌来解冟뀂就是在服务器每ơ生成一个不同的idq回l客LQ同时保存在session里,? L提交表单时必Lq个id也返回服务器Q程序首先比较返回的id与保存在session里的值是否一_如果不一致则说明本次操作已经被提交过了。可 以参看《J2EE核心模式》关于表C层模式的部分。需要注意的是对于用javascript window.open打开的窗口,一般不讄q个idQ? 或者用单独的idQ以防主H口无法操作Q徏议不要再window.open打开的窗口里做修Ҏ作,q样可以不用设|?br />
9、ؓ什么在Weblogic Server中改变session的值后要重新调用一ơsession.setValue
做这个动作主要是Z在集环境中提示Weblogic Server session中的值发生了改变Q需要向其他服务器进E复制新的session倹{?br />
10、ؓ什么session不见?br />? 除session正常失效的因素之外,服务器本w的可能性应该是微乎其微的,虽然W者在iPlanet6SP1加若q补丁的Solaris版本上倒也遇到 q;览器插件的可能性次之,W者也遇到q?721插g造成的问题;理论上防火墙或者代理服务器在cookie处理上也有可能会出现问题?br />出现q一问题的大部分原因都是E序的错误,最常见的就是在一个应用程序中去访问另外一个应用程序。我们在下一节讨个问题?br />
七、跨应用E序的session׃n

? 常有q样的情况,一个大目被分割成若干项目开发,Z能够互不q扰Q要求每个小目作ؓ一个单独的web应用E序开发,可是C最后突然发现某几个? 目之间需要共享一些信息,或者想使用session来实现SSO(single sign on)Q在session中保存login的用户信息,最? 然的要求是应用程序间能够讉K彼此的session?br />
然而按照Servlet规范Qsession的作用范围应该仅仅限于当前应用程? 下,不同的应用程序之间是不能够互相访问对方的session的。各个应用服务器从实际效果上都遵守了q一规范Q但是实现的l节却可能各有不同,因此解决 跨应用程序session׃n的方法也各不相同?br />
首先来看一下Tomcat是如何实现web应用E序之间session的隔ȝQ从  Tomcat讄的cookie路径来看Q它对不同的应用E序讄的cookie路径是不同的Q这样不同的应用E序所用的session id是不? 的,因此即在同一个浏览器H口里访问不同的应用E序Q发送给服务器的session id也可以是不同的?br />

  

Ҏq个Ҏ,我们可以推测Tomcat中session的内存结构大致如下?br />



W? 者以前用q的iPlanet也采用的是同L方式Q估计SunONE与iPlanet之间不会有太大的差别。对于这U方式的服务器,解决的思\很简单,? 际实行v来也不难。要么让所有的应用E序׃n一个session idQ要么让应用E序能够获得其他应用E序的session id?br />
iPlanet中有一U很单的Ҏ来实现共享一个session idQ那是把各个应用程序的cookie路径都设?Q实际上应该?NASAppQ对于应用程序来讲它的作用相当于根)?br /><session-info>
<path>/NASApp</path>
</session-info>

需 要注意的是,操作׃n的session应该遵@一些编E约定,比如在session attribute名字的前面加上应用程序的前缀Q?  setAttribute("name", "neo")变成setAttribute("app1.name", "neo")Q以防止命名I间? H,D互相覆盖?br />

在Tomcat中则没有q么方便的选择。在Tomcat版本3上,我们q可以有一些手D|׃n session。对于版?以上的TomcatQ目前笔者尚未发现简单的办法。只能借助于第三方的力量,比如使用文g、数据库、JMS或者客L cookieQURL参数或者隐藏字D늭手段?br />
我们再看一下Weblogic Server是如何处理session的?br />

  

? 截屏画面上可以看到Weblogic ServerҎ有的应用E序讄的cookie的\径都?Q这是不是意味着在Weblogic Server? 默认的就可以׃nsession了呢Q然而一个小实验卛_证明即不同的应用程序用的是同一个sessionQ各个应用程序仍然只能访问自己所讄的那 些属性。这说明Weblogic Server中的session的内存结构可能如?br />



对于q样一U结构,?  session机制本n上来解决session׃n的问题应该是不可能的了。除了借助于第三方的力量,比如使用文g、数据库、JMS或者客L  cookieQURL参数或者隐藏字D늭手段Q还有一U较为方便的做法Q就是把一个应用程序的session攑ֈServletContext中,q样 另外一个应用程序就可以从ServletContext中取得前一个应用程序的引用。示例代码如下,

应用E序A
context.setAttribute("appA", session); 

应用E序B
contextA = context.getContext("/appA");
HttpSession sessionA = (HttpSession)contextA.getAttribute("appA"); 

值得注意的是q种用法不可ULQ因为根据ServletContext的JavaDocQ应用服务器可以处于安全的原因对于context.getContext("/appA");q回I|以上做法在Weblogic Server 8.1中通过?br />
? 么Weblogic ServerZ么要把所有的应用E序的cookie路径都设?呢?原来是ؓ了SSOQ凡是共享这个session的应用程序都? 以共享认证的信息。一个简单的实验可以证明这一点,修改首先d的那个应用程序的描述Wweblogic.xmlQ把cookie路径修改? /appA 讉K另外一个应用程序会重新要求dQ即使是反过来,先访问cookie路径?的应用程序,再访问修改过路径的这个,虽然不再提示dQ但 是登录的用户信息也会丢失。注意做q个实验时认证方式应该用FORMQ因为浏览器和web服务器对basic认证方式有其他的处理方式Q第二次h的认 证不是通过 session来实现的。具体请参看[7] secion 14.8 AuthorizationQ你可以修改所附的CZE序来做q些试验?br />
八、ȝ
session机制本nq不复杂Q然而其实现和配|上的灵zL却使得具体情况复杂多变。这也要求我们不能把仅仅某一ơ的l验或者某一个浏览器Q服务器的经验当作普遍适用的经验,而是始终需要具体情况具体分析?br />? 要:虽然session机制在web应用E序中被采用已经很长旉了,但是仍然有很多h不清楚session机制的本质,以至不能正确的应用这一技术。本 文将详细讨论session的工作机制ƈ且对在Java web application中应用session机制时常见的问题作出解答?img src ="http://www.aygfsteel.com/wadise/aggbug/45273.html" width = "1" height = "1" />

wadise 2006-05-09 20:26 发表评论
]]>
Adobe Acrobat 7.0下蝲地址Q不是Adobe Acrobat Readerhttp://www.aygfsteel.com/wadise/archive/2006/03/03/33497.htmlwadisewadiseFri, 03 Mar 2006 08:53:00 GMThttp://www.aygfsteel.com/wadise/archive/2006/03/03/33497.htmlhttp://www.aygfsteel.com/wadise/comments/33497.htmlhttp://www.aygfsteel.com/wadise/archive/2006/03/03/33497.html#Feedback0http://www.aygfsteel.com/wadise/comments/commentRss/33497.htmlhttp://www.aygfsteel.com/wadise/services/trackbacks/33497.htmlURL http://219.149.54.89/Software/SoftDown.asp?ID=33

wadise 2006-03-03 16:53 发表评论
]]>
如何把Hibernate2.1升到Hibernate3.0Q?/title><link>http://www.aygfsteel.com/wadise/archive/2006/03/02/33114.html</link><dc:creator>wadise</dc:creator><author>wadise</author><pubDate>Thu, 02 Mar 2006 00:55:00 GMT</pubDate><guid>http://www.aygfsteel.com/wadise/archive/2006/03/02/33114.html</guid><wfw:comment>http://www.aygfsteel.com/wadise/comments/33114.html</wfw:comment><comments>http://www.aygfsteel.com/wadise/archive/2006/03/02/33114.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.aygfsteel.com/wadise/comments/commentRss/33114.html</wfw:commentRss><trackback:ping>http://www.aygfsteel.com/wadise/services/trackbacks/33114.html</trackback:ping><description><![CDATA[<TABLE width="97%" border=0> <TBODY> <TR> <TD width="94%"> <DIV align=left><FONT size=4>如何把Hibernate2.1升到Hibernate3.0Q?</FONT></DIV> <P align=left><FONT size=2>选自<<_NHibernateQJava对象持久化技术详?gt;> 作者:<A ><FONT color=#996666>孙卫?/FONT></A> 来源:www.javathinker.org<BR>如果转蝲Q请标明出处Q谢?BR></FONT></P></TD></TR> <TR> <TD width="94%"> <P><BR><A ><FONT color=#999999>1.1 Hibernate API 变化 </FONT></A><BR><A ><FONT color=#999999>1.1.1 包名 </FONT></A><BR><A ><FONT color=#999999>1.1.2 org.hibernate.classic?</FONT></A><BR><A ><FONT color=#999999>1.1.3 Hibernate所依赖的第三方软g?/FONT></A> <BR><A ><FONT color=#999999>1.1.4 异常模型 </FONT></A><BR><A ><FONT color=#999999>1.1.5 Session接口</FONT></A> <BR><A ><FONT color=#999999>1.1.6 createSQLQuery() </FONT></A><BR><A ><FONT color=#999999>1.1.7 Lifecycle ?Validatable 接口 </FONT></A><BR><A ><FONT color=#999999>1.1.8 Interceptor接口 </FONT></A><BR><A ><FONT color=#999999>1.1.9 UserType和CompositeUserType接口 </FONT></A><BR><A ><FONT color=#999999>1.1.10 FetchModec?</FONT></A><BR><A ><FONT color=#999999>1.1.11 PersistentEnumc?</FONT></A><BR><A ><FONT color=#999999>1.1.12 对Blob 和Clob的支?</FONT></A><BR><A ><FONT color=#999999>1.1.13 Hibernate中供扩展的API的变?</FONT></A><BR><A ><FONT color=#999999>1.2 元数据的变化 </FONT></A><BR><A ><FONT color=#999999>1.2.1 索策?</FONT></A><BR><A ><FONT color=#999999>1.2.2 对象标识W的映射 </FONT></A><BR><A ><FONT color=#999999>1.2.3 集合映射 </FONT></A><BR><A ><FONT color=#999999>1.2.4 DTD</FONT></A> <BR><A ><FONT color=#999999>1.3 查询语句的变?</FONT></A><BR><A ><FONT color=#999999>1.3.1 indices()和elements()函数</FONT></A> </P> <P><BR>管Hibernate 3.0 与Hibernate2.1的源代码是不兼容的,但是当Hibernate开发小l在设计Hibernate3.0Ӟ为简化升UHibernate版本作了周到的考虑。对于现有的ZHibernate2.1的Java目Q可以很方便的把它升U到Hibernate3.0?BR><BR>本文描述了Hibernate3.0版本的新变化QHibernate3.0版本的变化包括三个方面:<BR>Q?QAPI的变化,它将影响到JavaE序代码?BR>Q?Q元数据Q它媄响到对象-关系映射文g?BR>Q?QHQL查询语句?BR><BR>值得注意的是Q?Hibernate3.0q不会完全取代Hibernate2.1。在同一个应用程序中Q允许Hibernate3.0和Hibernate2.1q存?BR><BR><A name=11></A>1.1 Hibernate API 变化<BR><BR><A name=111></A>1.1.1 包名<BR><BR>Hibernate3.0的包的根路径? “org.hibernate?Q而在Hibernate2.1中ؓ“net.sf.hibernate”。这一命名变化使得Hibernate2.1和Hibernate3.0能够同时在同一个应用程序中q行?BR><BR>如果希望把已有的应用升到Hibernate3.0Q那么升U的W一步是把Java源程序中的所有“net.sf.hibernate”替换ؓ“org.hibernate”?BR><BR>Hibernate2.1中的“net.sf.hibernate.expression”包被改名ؓ“org.hibernate.criterion”。假如应用程序用了Criteria APIQ那么在升的过E中Q必LJava源程序中的所有“net.sf.hibernate.expression”替换ؓ“org.hibernate.criterion”?BR><BR>如果应用使用了除Hibernate以外的其他外部YӞ而这个外部Y件又引用了Hibernate的接口,那么在升U时必须十分心。例如EHCache拥有自己的CacheProviderQ?net.sf.ehcache.hibernate.ProviderQ在q个cM引用了Hibernate2.1中的接口Q在升应用Ӟ可以采用以下办法之一来升UEHCache:<BR><BR>Q?Q手工修改net.sf.ehcache.hibernate.Providerc,使它引用Hibernate3.0中的接口?BR>Q?Q等到EHCache软g本n升Z用Hibernate3.0后,使用新的EHCache软g?BR>Q?Q用Hibernate3.0中内|的CacheProviderQorg.hibernate.cache.EhCacheProvider?BR><BR><A name=112></A>1.1.2 org.hibernate.classic?BR><BR>Hibernate3.0把一些被废弃的接口都转移到org.hibernate.classic中?BR><BR><A name=113></A>1.1.3 Hibernate所依赖的第三方软g?BR><BR>在Hibernate3.0的Y件包的lib目录下的README.txt文g中,描述了Hibernate3.0所依赖的第三方软g包的变化?BR><BR><A name=114></A>1.1.4 异常模型<BR><BR>在Hibernate3.0中,HibernateException异常以及它的所有子c都l承了java.lang.RuntimeException。因此在~译Ӟ~译器不会再查HibernateException?BR><BR><A name=115></A>1.1.5 Session接口<BR><BR>在Hibernate3.0中,原来Hibernate2.1的Session接口中的有些基本Ҏ也被废弃Q但Z化升U,q些Ҏ依然是可用的Q可以通过org.hibernate.classic.Session子接口来讉K它们Q例如:<BR></P> <P><FONT size=2>org.hibernate.classic.Session session=sessionFactory.openSession();<BR>session.delete("delete from Customer ");<BR></FONT></P> <P>在Hibernate3.0中,org.hibernate.classic.Session接口l承了org.hibernate.Session接口Q在org.hibernate.classic.Session接口中包含了一pd被废弃的ҎQ如find()、interate(){。SessionFactory接口的openSession()Ҏq回org.hibernate.classic.Sessioncd的实例。如果希望在E序中完全用Hibernate3.0Q可以采用以下方式创建Session实例Q?BR><BR><FONT size=2>org.hibernate.Session session=sessionFactory.openSession();</FONT><BR><BR>如果是对已有的程序进行简单的升Qƈ且希望仍然调用Hibernate2.1中Session的一些接口,可以采用以下方式创徏Session实例Q?BR><BR><FONT size=2>org.hibernate.classic.Session session=sessionFactory.openSession();</FONT><BR><BR>在Hibernate3.0中,Session接口中被废弃的方法包括:<BR>* 执行查询的方法:find()、iterate()、filter()和delete(String hqlSelectQuery) <BR>* saveOrUpdateCopy()<BR><BR>Hibernate3.0一律采用createQuery()Ҏ来执行所有的查询语句Q采用DELETE 查询语句来执行批量删除,采用merge()Ҏ来替?saveOrUpdateCopy()Ҏ?/P> <P><BR><I>提示Q在Hibernate2.1中,Session的delete()Ҏ有几U重载Ş式,其中参数为HQL查询语句的delete()Ҏ在Hibernate3.0中被废弃Q而参CؓOjbectcd的的delete()Ҏ依然被支持。delete(Object o)Ҏ用于删除参数指定的对象,该方法支持联删除?/I></P> <P>Hibernate2.1没有Ҏ量更新和扚w删除提供很好的支持,参见<<_NHibernate>>一书的W?3章的13.1.1节(扚w更新和批量删除)Q而Hibernate3.0Ҏ量更新和扚w删除提供了支持,能够直接执行扚w更新或批量删除语句,无需把被更新或删除的对象先加载到内存中。以下是通过Hibernate3.0执行扚w更新的程序代码:</P> <P><FONT size=2>Session session = sessionFactory.openSession();<BR>Transaction tx = session.beginTransaction();</FONT></P> <P><FONT size=2>String hqlUpdate = "update Customer set name = :newName where name = :oldName";<BR>int updatedEntities = s.createQuery( hqlUpdate )<BR>.setString( "newName", newName )<BR>.setString( "oldName", oldName )<BR>.executeUpdate();<BR>tx.commit();<BR>session.close();</FONT></P> <P>以下是通过Hibernate3.0执行扚w删除的程序代码:</P> <P><FONT size=2>Session session = sessionFactory.openSession();<BR>Transaction tx = session.beginTransaction();</FONT></P> <P><FONT size=2>String hqlDelete = "delete Customer where name = :oldName";<BR>int deletedEntities = s.createQuery( hqlDelete )<BR>.setString( "oldName", oldName )<BR>.executeUpdate();<BR>tx.commit();<BR>session.close();</FONT><BR><BR><A name=116></A>1.1.6 createSQLQuery()<BR><BR>在Hibernate3.0中,Session接口的createSQLQuery()Ҏ被废弃,被移到org.hibernate.classic.Session接口中。Hibernate3.0采用新的SQLQuery接口来完成相同的功能?BR><BR><A name=117></A>1.1.7 Lifecycle ?Validatable 接口<BR><BR>Lifecycle和Validatable 接口被废弃,q且被移到org.hibernate.classic包中?BR><BR><A name=118></A>1.1.8 Interceptor接口<BR><BR>在Interceptor 接口中加入了两个新的Ҏ?用户创徏的Interceptor实现cd升的过E中Q需要ؓq两个新Ҏ提供Ҏ体ؓI的实现。此外,instantiate()Ҏ的参C了修改,isUnsaved()Ҏ被改名ؓisTransient()?BR><BR><A name=119></A>1.1.9 UserType和CompositeUserType接口<BR><BR>在UserType和CompositeUserType接口中都加入了一些新的方法,q两个接口被Udorg.hibernate.usertype包中Q用户定义的UserType和CompositeUserType实现cdd现这些新Ҏ?/P> <P>Hibernate3.0提供了ParameterizedType接口Q用于更好的重用用户自定义的cd?/P> <P><A name=1110></A>1.1.10 FetchModec?BR><BR>FetchMode.LAZY ?FetchMode.EAGER被废弃。取而代之的分别为FetchMode.SELECT 和FetchMode.JOIN?BR><BR><A name=1111></A>1.1.11 PersistentEnumc?BR><BR>PersistentEnum被废弃ƈ删除。已l存在的应用应该采用UserType来处理枚丄型?BR><BR><A name=1112></A>1.1.12 对Blob 和Clob的支?BR><BR>Hibernate对Blob和Clob实例q行了包装,使得那些拥有Blob或Clobcd的属性的cȝ实例可以被游R序列化或反序列化,以及传递到merge()Ҏ中?BR><BR><A name=1113></A>1.1.13 Hibernate中供扩展的API的变?BR><BR>org.hibernate.criterion?org.hibernate.mapping?org.hibernate.persister和org.hibernate.collection 包的l构和实现发生了重大的变化。多数基于Hibernate <BR>2.1 的应用不依赖于这些包Q因此不会被影响。如果你的应用扩展了q些包中的类Q那么必非常小心的对受影响的程序代码进行升U?BR><BR><A name=12></A>1.2 元数据的变化<BR><BR><A name=121></A>1.2.1 索策?BR><BR>在Hibernate2.1中,lazy属性的默认gؓ“false”,而在Hibernate3.0中,lazy属性的默认gؓ“true”。在升映射文gӞ如果原来的映文件中的有兛_素,?lt;set>?lt;class>{没有显式设|lazy属性,那么必须把它们都昑ּ的设|ؓlazy=“true”。如果觉得这U升U方式很ȝQ可以采取另一单的升方式Q在<hibernate-mapping>元素中设|? default-lazy=“false”?<BR><BR><A name=122></A>1.2.2 对象标识W的映射<BR><BR>unsaved-value属性是可选的Q在多数情况下,Hibernate3.0把unsaved-value="0" 作ؓ默认倹{?BR><BR>在Hibernate3.0中,当用自然主键和游离对象Ӟ不再实现Interceptor.isUnsaved()Ҏ?如果没有讄q个ҎQ当Hibernate3.0无法区分对象的状态时Q会查询数据库,来判断这个对象到底是临时对象Q还是游d象。不q,昑ּ的用Interceptor.isUnsaved()Ҏ会获得更好的性能Q因可以减少Hibernate直接讉K数据库的ơ数?BR><BR><A name=123></A>1.2.3 集合映射<BR><BR><index>元素在某些情况下?lt;list-index>?lt;map-key>元素替代。此外,Hibernate3.0?lt;map-key-many-to-many> 元素来替代原来的<key-many-to-many>.元素Q用<composite-map-key>元素来替代原来的<composite-index>元素?BR><BR><A name=124></A>1.2.4 DTD<BR><BR>对象-关系映射文g中的DTD文档Q由原来的:<BR>http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd <BR>改ؓQ?BR>http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd<BR><BR><A name=13></A>1.3 查询语句的变?BR><BR>Hibernate3.0 采用新的ZANTLR的HQL/SQL查询译器,不过QHibernate2.1的查询翻译器也依然存在。在Hibernate的配|文件中Qhibernate.query.factory_class属性用来选择查询译器。例如:<BR>Q?Q选择Hibernate3.0的查询翻译器Q?BR>hibernate.query.factory_class= org.hibernate.hql.ast.ASTQueryTranslatorFactory<BR>Q?Q选择Hibernate2.1的查询翻译器<BR>hibernate.query.factory_class= org.hibernate.hql.classic.ClassicQueryTranslatorFactory</P> <P><BR><I>提示QANTLR是用UJava语言~写出来的一个编译工P它可生成Java语言或者是C++的词法和语法分析器,q可产生语法分析树ƈ对该树进行遍历。ANTLR׃是纯Java的,因此可以安装在Q意^CQ但是需要JDK的支持?/I></P> <P>Hibernate开发小l尽力保证Hibernate3.0的查询翻译器能够支持Hibernate2.1的所有查询语句。不q,对于许多已经存在的应用,在升U过E中Q也不妨仍然使用Hibernate2.1的查询翻译器?BR>值得注意的是Q?Hibernate3.0的查询翻译器存在一个BugQ不支持某些theta-styleq结查询方言Q如Oracle8i的OracleDialect方言、Sybase11Dialect。解册一问题的办法有两种Q(1Q改Z用支持ANSI-styleq结查询的方aQ如 Oracle9Dialect,Q?Q如果升U的时候遇到这一问题Q那么还是改Z用Hibernate2.1的查询翻译器?BR><BR><A name=131></A>1.3.1 indices()和elements()函数<BR><BR>在HQL的select子句中废弃了indices()和elements()函数Q因两个函数的语法很让用戯解,可以用显式的q接查询语句来替?select elements(...) 。而在HQL的where子句中,仍然可以使用elements()函数?BR></P></TD></TR></TBODY></TABLE><img src ="http://www.aygfsteel.com/wadise/aggbug/33114.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wadise/" target="_blank">wadise</a> 2006-03-02 08:55 <a href="http://www.aygfsteel.com/wadise/archive/2006/03/02/33114.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>isAssignableFrom和instanceof的不?/title><link>http://www.aygfsteel.com/wadise/archive/2005/12/14/23803.html</link><dc:creator>wadise</dc:creator><author>wadise</author><pubDate>Wed, 14 Dec 2005 04:08:00 GMT</pubDate><guid>http://www.aygfsteel.com/wadise/archive/2005/12/14/23803.html</guid><description><![CDATA[<P><FONT size=1>下面是JUnit的测试代?试能通过)Q?/P> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080"> 1</SPAN><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">        User user </SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000"> </SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000"> User();<BR></SPAN><SPAN style="COLOR: #008080"> 2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertTrue(user.getClass().isAssignableFrom(User.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080"> 3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertFalse(user.getClass().isAssignableFrom(Actor.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080"> 4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertFalse(user.getClass().isAssignableFrom(IUser.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080"> 5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertFalse(user.getClass().isAssignableFrom(IActor.</SPAN><SPAN style="COLOR: #0000ff">class</SPAN><SPAN style="COLOR: #000000">));<BR></SPAN><SPAN style="COLOR: #008080"> 6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        <BR></SPAN><SPAN style="COLOR: #008080"> 7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertTrue(user </SPAN><SPAN style="COLOR: #0000ff">instanceof</SPAN><SPAN style="COLOR: #000000"> User);<BR></SPAN><SPAN style="COLOR: #008080"> 8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertTrue(user </SPAN><SPAN style="COLOR: #0000ff">instanceof</SPAN><SPAN style="COLOR: #000000"> Actor);<BR></SPAN><SPAN style="COLOR: #008080"> 9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>        assertTrue(user </SPAN><SPAN style="COLOR: #0000ff">instanceof</SPAN><SPAN style="COLOR: #000000"> IUser);<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top>       assertTrue(user </SPAN><SPAN style="COLOR: #0000ff">instanceof</SPAN><SPAN style="COLOR: #000000"> IActor);</SPAN></DIV></FONT><BR><FONT size=1>cMcM间的层次关系是:<BR> <DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><IMG src="http://www.aygfsteel.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">User extend Actor </SPAN><SPAN style="COLOR: #0000ff">implements</SPAN><SPAN style="COLOR: #000000"> IUser</SPAN></DIV></FONT><BR><FONT size=1>从上面可以看出isAssignableFrom和instanceof的不同之处?/FONT><img src ="http://www.aygfsteel.com/wadise/aggbug/23803.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.aygfsteel.com/wadise/" target="_blank">wadise</a> 2005-12-14 12:08 <a href="http://www.aygfsteel.com/wadise/archive/2005/12/14/23803.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <a href="http://www.aygfsteel.com/" title="狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频">狠狠久久亚洲欧美专区_中文字幕亚洲综合久久202_国产精品亚洲第五区在线_日本免费网站视频</a> </div> </footer> վ֩ģ壺 <a href="http://" target="_blank">ؿ˹</a>| <a href="http://" target="_blank">ˮ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ƾ</a>| <a href="http://" target="_blank">ƽ</a>| <a href="http://" target="_blank">̷</a>| <a href="http://" target="_blank">ԫ</a>| <a href="http://" target="_blank">ɽ</a>| <a href="http://" target="_blank">⴨</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ְ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">β</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ʱ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank">Ϫ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">º</a>| <a href="http://" target="_blank">¡</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">ͼ</a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank"></a>| <a href="http://" target="_blank">Ϲ</a>| <a href="http://" target="_blank">Ͽ</a>| <a href="http://" target="_blank">»</a>| <a href="http://" target="_blank">ԭƽ</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>