replicate session in clustering weblogic v10.3

本文介绍如何在WebLogic服务器集群中配置会话复制,确保应用在不同实例间能够共享HTTP会话状态。通过修改weblogic.xml文件,设置持久化存储类型为集群内复制,启用会话共享,并配置其他相关选项。

Even set 2 weblogic instances as clustering servers, the session can not be replicated by default.

let's we have the code to get session as follows.
HttpSession session = request.getSession();
Object myObj = session.getAttribute("myObjKey");

 If want to replicate the session during clustering weblogic instances, need to modify weblogic.xml as follows.

<?xml version='1.0' encoding='UTF-8'?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd">

    <session-descriptor>
        <persistent-store-type>replicated_if_clustered</persistent-store-type>
        <sharing-enabled>true</sharing-enabled> 
    </session-descriptor>

    <container-descriptor>
        <prefer-web-inf-classes>true</prefer-web-inf-classes>
    </container-descriptor>

    <context-root>/mycontext</context-root>

</weblogic-web-app>

-- persistent-store-type
    Sets the persistent store method to one of the following options:

  • memory —Disables persistent session storage.
  • replicated —Same as memory , but session data is replicated across the clustered servers.
  • replicated_if_clustered—If the Web application is deployed on a clustered server, the in-effect persistent-store-type will be replicated. Otherwise, memory is the default.
  • async-replicated—Enables asynchronous session replication in an application or web application. See Configuring Session Persistence.
  • async-replicated-if-clustered—Enables asynchronous session replication in an application or web application when deployed to a cluster environment. If deployed to a single server environment, then the session persistence/replication defaults to in-memory. This allows testing on a single server without deployment errors.
  • file —Uses file-based persistence (See also persistent-store-dir ).
  • async-jdbc —Enables asynchronous JDBC persistence for HTTP sessions in an application or web application. See Configuring Session Persistence.
  • jdbc —Uses a database to store persistent sessions. (see also persistent-store-pool ).
  • cookie—All session data is stored in a cookie in the user’s browser.

--  sharing-enabled
     Enables Web applications to share HTTP sessions when the value is set to true at the application level.

     This element is ignored if turned on at the Web application level. 
 
--  prefer-web-inf-classes
     if set to true, will cause classes located in the WEB-INF directory of a Web application to be loaded in    preference to classes loaded in the application or system classloader. The default value is false. A value specified in the console will take precedence over a value set manually. 
 
--  context-root

The context-root element defines the context root of this stand-alone Web application. If the Web application is part of an EAR, not stand-alone, specify the context root in the EAR’s META-INF/application.xml file. A context-root setting in application.xml takes precedence over context-root setting in weblogic.xml.

Note that this weblogic.xml element only acts on deployments using the two-phase deployment model.
The order of precedence for context root determination for a Web application is as follows:
  1. Check application.xml for context root; if found, use as Web application’s context root.
  2. If context root is not set in application.xml, and the Web application is being deployed as part of an EAR, check whether context root is defined in weblogic.xml. If found, use as Web application’s context root. If the Web application is deployed standalone, application.xml does not come into play and the determination for context-root starts at weblogic.xml and defaults to URI if it is not defined there.
  3. If context root is not defined in weblogic.xml or application.xmll, then infer the context path from the URI, giving it the name of the value defined in the URI minus the WAR suffix. For instance, a URI MyWebApp.war would be named MyWebApp.

Note: The context-root element cannot be set for individual Web applications in EAR libraries. It can only bet set for Web application libraries.
`REPLICATE` 函数是 SQL Server 中用于将字符串重复指定次数的函数,在隐藏外国人姓名前几个字符的场景中可以发挥作用。以下是该函数的详细使用方法: ### 函数语法 `REPLICATE` 函数的基本语法如下: ```sql REPLICATE(string_expression, integer_expression) ``` 其中: - `string_expression`:要重复生成的字符串表达式,可以是字符或二进制数据类型的表达式,也可以是字符串或二进制数据[^2][^3][^4]。 - `integer_expression`:重复次数,必须是一个正整数,为任何整数类型的表达式,包括 `bigint`。如果 `integer_expression` 为负,则返回 `NULL`[^2][^4]。 ### 函数返回类型 返回与 `string_expression` 相同的数据类型。如果 `string_expression` 的类型不是 `varchar(max)` 或 `nvarchar(max)`,则 `REPLICATE` 将返回值截断为 8000 字节;若要返回大于 8000 字节的值,则必须将 `string_expression` 显式转换为适当的大值数据类型[^4]。 ### 使用示例 #### 基础用法 ```sql SELECT REPLICATE(&#39;abc&#39;, 3); -- 结果:abcabcabc ``` 此示例将字符串 `&#39;abc&#39;` 重复 3 次,得到 `&#39;abcabcabc&#39;`。 #### 结合其他函数使用 ```sql SELECT LEFT(REPLICATE(&#39;abc&#39;,3),5); -- 结果:abcab ``` 此示例先使用 `REPLICATE` 函数将字符串 `&#39;abc&#39;` 重复 3 次,得到 `&#39;abcabcabc&#39;`,再使用 `LEFT` 函数截取前 5 个字符,最终结果为 `&#39;abcab&#39;`。 #### 动态使用 ```sql DECLARE @n INT = 5; DECLARE @str VARCHAR(10) = &#39;X&#39;; SELECT REPLICATE(@str, @n) AS Result; -- 结果:XXXXX ``` 此示例通过变量 `@n` 动态指定重复次数,将字符串 `&#39;X&#39;` 重复 5 次,得到 `&#39;XXXXX&#39;`。 #### 在隐藏外国人姓名前几个字符中的应用 假设有一个 `people` 表,其中有 `name` 列存储外国人姓名,要隐藏前 3 个字符,可以使用以下 SQL 语句: ```sql SELECT REPLICATE(&#39;*&#39;, 3) + SUBSTRING(name, 4, LEN(name)) AS hidden_name FROM people; ``` 此示例使用 `REPLICATE` 函数生成 3 个 `*` 字符,再使用 `SUBSTRING` 函数截取姓名从第 4 个字符开始的部分,最后将两者拼接起来,实现隐藏姓名前 3 个字符的效果。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值