首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

关于url传递sessionid的有关问题

2012-02-01 
关于url传递sessionid的问题jsp如果用url在地址栏直接传sessionid为什么一定要用分号如此例http://localho

关于url传递sessionid的问题
jsp如果用url在地址栏直接传sessionid为什么一定要用分号如此例http://localhost:8080/jsp7/MyJsp.jsp;jsessionid=EBFA3819CF9125CA92193279BDA92CCC
我试了好多次,就是myjsp.jsp这里不能用?号,只有用;号才能传过去,希望有朋友能详细的为小弟解说一下

[解决办法]
tomcat处理url传过来的session代码如下:

Java code
 /**     * Parse session id in URL.     */    protected void parseSessionId(org.apache.coyote.Request req, Request request) {        ByteChunk uriBC = req.requestURI().getByteChunk();        int semicolon = uriBC.indexOf(match, 0, match.length(), 0);        if (semicolon > 0) {            // Parse session ID, and extract it from the decoded request URI            int start = uriBC.getStart();            int end = uriBC.getEnd();            int sessionIdStart = semicolon + match.length();            int semicolon2 = uriBC.indexOf(';', sessionIdStart);//看这行,就知道为什么是;了            if (semicolon2 >= 0) {                request.setRequestedSessionId                    (new String(uriBC.getBuffer(), start + sessionIdStart,                             semicolon2 - sessionIdStart));                // Extract session ID from request URI                byte[] buf = uriBC.getBuffer();                for (int i = 0; i < end - start - semicolon2; i++) {                    buf[start + semicolon + i]                         = buf[start + i + semicolon2];                }                uriBC.setBytes(buf, start, end - start - semicolon2 + semicolon);            } else {                request.setRequestedSessionId                    (new String(uriBC.getBuffer(), start + sessionIdStart,                             (end - start) - sessionIdStart));                uriBC.setEnd(start + semicolon);            }            request.setRequestedSessionURL(true);        } else {            request.setRequestedSessionId(null);            request.setRequestedSessionURL(false);        }    } 

热点排行