订阅所有JSP/Servlet的日志 订阅 | 这是最新一篇日志 上一篇 | 下一篇日志 下一篇 ]
解决方案

三级中文子域名支持的探索

由于CJW支持中文用户名,三级中文子域名泛解析比如 永远的最爱JAVA.blog.chinajavaworld.com,解析没有问题。但在应用过程上遇到了两个问题:

1.在地址栏中输入
1
http://永远的最爱JAVA.blog.chinajavaworld.com/

在应用服务器中 request.getServerName() 得到的中文是乱码。即:??????????java.blog.chinajavaworld.com.

研读Resin源码,找到 com.caucho.server.http.HttpRequest 类,加入两行代码以支持 request.getServerName()的中文问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
  /**
   * Parses headers from the read stream.
   *
   * @param s the input read stream
   */
  private void parseHeaders(ReadStream s) throws IOException
  {
    // This is still slowest part of the web server.  I don't see how
    // to improve it much more, but there must be a way.
    int version = getVersion();
 
    if (version < HTTP_1_0) {
      return;
    }
 
    if (version < HTTP_1_1)
      killKeepalive();
 
    byte []readBuffer = s.getBuffer();
    int readOffset = s.getOffset();
    int readLength = s.getLength();
 
    char []headerBuffer = _headerBuffer;
    int headerOffset = 1;
    int headerBufferSize = headerBuffer.length;
    headerBuffer[0] = 'z';
    int headerSize = 0;
    _headerSize = 0;
 
    CharSegment []headerKeys = _headerKeys;
    CharSegment []headerValues = _headerValues;
 
    boolean debug = log.isLoggable(Level.FINE);
 
    while (true) {
      int ch;
 
      int keyOffset = headerOffset;
 
      // scan the key
      while (true) {
        if (readLength <= readOffset) {
          readOffset = 0;
          if ((readLength = s.fillBuffer()) <= 0)
            return;
        }
        ch = readBuffer[readOffset++];
 
        if (ch == '\n') {
          s.setOffset(readOffset);
          return;
        }
        else if (ch == ':')
          break;
 
        headerBuffer[headerOffset++] = (char) ch;
      }
 
      while (headerBuffer[headerOffset - 1] == ' ')
        headerOffset--;
 
      int keyLength = headerOffset - keyOffset;
      headerKeys[headerSize].init(headerBuffer, keyOffset, keyLength);
 
      do {
        if (readLength <= readOffset) {
          readOffset = 0;
          if ((readLength = s.fillBuffer()) <= 0)
            return;
        }
        ch = readBuffer[readOffset++];
      } while (ch == ' ' || ch == '\t');
 
      int valueOffset = headerOffset;
 
      // scan the value
      while (true) {
        if (readLength <= readOffset) {
          readOffset = 0;
          if ((readLength = s.fillBuffer()) <= 0)
            break;
        }
 
        if (ch == '\n') {
          int ch1 = readBuffer[readOffset];
 
          if (ch1 == ' ' || ch1 == '\t') {
            ch = ' ';
            readOffset++;
 
            if (headerBuffer[headerOffset - 1] == '\r')
              headerOffset--;
          }
          else
            break;
        }
 
        headerBuffer[headerOffset++] = (char) ch;
 
        ch = readBuffer[readOffset++];
      }
      
      //加入以下两行代码,设置_host
      String readStr = new String(readBuffer);
      _host = readStr.split("Host:")[1].split("\n")[0];
 
      while (headerBuffer[headerOffset - 1] <= ' ')
        headerOffset--;
 
      int valueLength = headerOffset - valueOffset;
      headerValues[headerSize].init(headerBuffer, valueOffset, valueLength);
 
      if (debug) {
        log.fine(dbgId() +
                 headerKeys[headerSize] + ": " + headerValues[headerSize]);
      }
      
      if (addHeaderInt(headerBuffer, keyOffset, keyLength,
                       headerValues[headerSize])) {
        headerSize++;
      }
      
      _headerSize = headerSize;
    }
  }


修改并替换后重启Resin

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Protocol: HTTP/1.1
Scheme: http
Server Name: 永远的最爱java.blog.chinajavaworld.com:8080 
Server Port: 8080
Protocol: HTTP/1.1
Server Info: Resin/3.0.24
Remote Addr: 127.0.0.1
Remote Host: 127.0.0.1
Character Encoding: UTF-8
Content Length: -1
Content Type: null
Auth Type: null
HTTP Method: GET
...


可以发现request.getServerName()可以显示中文。

2.原以为这下可以解决问题了,第二个问题的发现很不好办:

域名中带有中文的,Cookie读取不到。这意味着中文用户名的用户登录后访问自己的博客或同样带中文域名的博客时,都处于未登录状态。这是Cookie的规范,只能想别的办法。

解决办法还是有,比如可以在登录系统登录成功后,产生一个key,将用户的认证信息通过这个key存进分布式Cache中,同时在定向到成功页面的同时,将这个key做为参数传过去,新页面接收到key后从分布式Cache中取认证信息,这种方法虽然可以解决,但这个key必须在所有相关操作页面传递,影响用户体验。

目前采取了折中的办法,如果用户名是非字母或数字的,就用用户ID做为三级子域名进行访问。

平均得分
(0 次评分)





文章来自: 本站原创
标签: 泛解析 域名 
评论: 15 | 查看次数: 2022
  • 共有 15 条评论
windowsjava [2008-11-05 16:05:58]
CJW的泛域名解析,是不是每个url都要经过一次解析和转向?或url重写。
游客 [2008-11-01 14:27:27]
游客 [2008-10-27 15:46:35]
Lord of the Rings Online Gold
Buy Lotro Gold
Sell LoTRO Gold
LoTRO CD Key
LoTRO Europe Gold
Cheap LoTRO Accounts
Lord of the Rings Online Power Leveling
Lord of the Rings online CD Key
Cheap Lotro Gold
Buy Lotro Gold | Lord Of The Rings Online Gold
Lotro Accounts
| Buy Lotro Accounts
Lord Of The Rings Online Power Leveling | Lord Of The Rings Online PowerLeveling
Lotro Cd Key | Lord Time Card
Lotro Gold | Lotro Gold Instant Delivery
lord of the rings online accounts | lord of the rings online accounts for sale
Lotro Power Leveling | Lotro Powerleveling
Lord Of The Rings Online Cd Key | Lord Of The Rings Online Time Card
Air Jordan Shoes
Warhammer Gold
Warhammer Online Gold
Warhammer Accounts
Warhammer Power Leveling
Warhammer Online Key
Warhammer Gold
Warhammer Online Gold
Warhammer Time Card
Warhammer CD Key
WAR gold
warhammer online gold
Buy WAR gold
Buy warhammer gold
Buy warhammer online gold
warhammer gold
WAR Accounts
warhammer Accounts
warhammer online Accounts
Buy WAR Accounts
warhammer Accounts for sale
Warhammer Power Leveling
Warhammer Online Power Leveling
War Power Leveling
Buy Warhammer Power Leveling
Warhammer PowerLeveling
Cheap Warhammer Power Leveling
Cheap Warhammer Online Power Leveling
Buy War Power Leveling
Warhammer EU Power Leveling
Cheap Warhammer Gold
Cheap Warhammer online gold
Buy Cheap Warhammer Gold
Buy WAR Gold
Warhammer EU Gold
Warhammer EU Power Leveling
Warhammer EU CD Key
Warhammer EU Accounts
Warhammer CD Key
Warhammer online CD Key
Warhammer Timecard
Buy Warhammer Time Card
Warhammer 60 days Time Card
Cheap WAR Accounts
Cheap warhammer Accounts
Cheap warhammer online Accounts
Buy Cheap WAR Accounts
buy Warhammer CD Key
buy Warhammer online CD Key
cheap Warhammer CD key
warhammer time card
Warhammer prepaid time card
游客 [2008-10-17 21:20:21]
游客 [2008-10-15 13:24:21]
游客 [2008-09-29 10:03:20]
游客 [2008-09-25 16:56:11]
Warhammer Gold
Warhammer Online Gold
Warhammer gold
cheap Warhammer gold
Warhammer Online gold
Warhammer gold
Buy WAR gold
Cheap Warhammer Gold
Buy warhammer online gold
cheap warhammer online gold
Buy warhammer gold
buy warhammer online gold
buy cheap warhammer gold
War Gold
Buy Warhammer Gold
Warhammer Online Gold
Warhammer Gold for sale
Cheap Warhammer Gold
Warhammer Accounts
Buy Warhammer Accounts
Cheap Warhammer Accounts
Warhammer Power leveling
War Power leveling
Warhammer Online Power Leveling
heap Warhammer Power Leveling
Warhammer CD Key
War CD Key
Warhammer Online CD Key
Warhammer Game Time Card
Warhammer Game Card
Buy Warhammer Online CD Key
Buy War Gold
Sell Warhammer Gold
Warhammer EU Gold
Warhammer Online EU Gold
Sell Warhammer Gold
Warhammer EU Gold
Buy War Gold
Warhammer Online EU Gold
Buy Cheap Warhammer Gold
Cheap warhammer EU gold
Cheap War Gold
Cheapest Warhammer Gold
Buy Cheap Warhammer Gold
Buy Warhammer Online Accounts
Buy WAR Accounts
Buy Warhammer Power Leveling
Warhammer Powerleveling
Buy WAR Power Leveling
Buy Cheap Warhammer Power Leveling
Buy Warhammer CD Key
Warhammer EU CD key
Buy Warhammer Online key
Warhammer Time Card
Buy Warhammer Time Card
LoTRO Gold
Lord of the Rings Online Gold
Buy Lotro Gold
Sell LoTRO Gold
LoTRO CD Key
LoTRO Europe Gold
Cheap LoTRO Accounts
Lord of the Rings Online Power Leveling
Lord of the Rings online CD Key
Cheap Lotro Gold
Buy Lotro Gold | Lord Of The Rings Online Gold
Lotro Accounts
| Buy Lotro Accounts
Lord Of The Rings Online Power Leveling | Lord Of The Rings Online PowerLeveling
Lotro Cd Key | Lord Time Card
Lotro Gold | Lotro Gold Instant Delivery
lord of the rings online accounts | lord of the rings online accounts for sale
Lotro Power Leveling | Lotro Powerleveling
Lord Of The Rings Online Cd Key | Lord Of The Rings Online Time Card
游客 [2008-09-24 16:39:27]
游客 [2008-09-22 15:41:49]
游客 [2008-09-09 15:31:03]
游客 [2008-09-04 15:23:24]
游客 [2008-08-06 16:34:50]
游客 [2008-05-26 09:32:57]
游客 [2008-05-26 09:32:15]
游客 [2008-05-20 14:30:21]
  • 共有 15 条评论
发表评论
昵 称:  登录
内 容:
选 项:
字数限制 1000 字 | UBB代码 开启 | [img]标签 开启