일반적인 문제 jsessionid가 뭐야?

jsessionid가 뭐야?

May 05, 2019 pm 02:15 PM

jsessionid는 쿠키입니다. URL 뒤에 ";jsessionid=xxx"를 추가하면 서블릿 컨테이너가 사용자 세션을 기록하는 데 사용됩니다. 사용자의 세션에 액세스합니다.

jsessionid가 뭐야?

먼저 JSESSIONID는 서블릿 컨테이너(tomcat, jetty)에서 사용자 세션을 기록하는 데 사용되는 쿠키입니다.

jsessionid가 뭐야?

JSESSIONID를 심을 때

세션을 생성할 때, 즉 request.getSession()이 호출될 때 getSession에 대해서는 언급하지 않겠습니다. 몇 가지 추가 사항은 JSP 페이지에 액세스하면 기본적으로 세션이 생성되지 않는다는 것입니다.

JSESSIONID 작동 원리:

jsessionid가 뭐야?

URL이 많습니다. 쓰기

서버는 메모리에 세션을 생성하고 쿠키가 필요합니다. 요청 헤더에 Set-Cookie를 설정하는 것 외에도 tomcat과 같은 컨테이너에는 URL 재작성 메커니즘이 있습니다. 이 메커니즘은 클라이언트 쿠키를 사용할 수 없을 때의 은폐 전략입니다. URL 뒤에;jsessionid=xxx를 추가하면 세션 ID가 전달되므로 쿠키를 사용할 수 없는 경우에도 세션의 가용성을 보장할 수 있습니다. 세션 자체가 URL에 노출되므로 안전하지 않습니다. 그러나 가장 중요한 질문은 tomcat이 클라이언트 쿠키를 사용할 수 없다는 것을 어떻게 알 수 있느냐는 것입니다. 아이디어에서 Tomcat의 소스 코드 디버깅 추적을 가져왔습니다. 버전마다 약간의 차이가 있지만 대략 동일해야 합니다. Tomcat에는 Response의 구현 클래스인 org.apache.catalina.connector.Response가 있습니다. URL 재작성을 위한 두 가지 방법은 각각 encodeRedirectURL과 encodeURL입니다. 리디렉션할 때 encodeRedirectURL이 호출되고, encodeURL은 수동으로 호출되는 것으로 보이므로 기본적으로 URL 재작성은 리디렉션할 때만 발생합니다. 두 메서드의 코드는 유사합니다. 다음은 encodeRedirectURL

/**
     * Encode the session identifier associated with this response
     * into the specified redirect URL, if necessary.
     *
     * @param url URL to be encoded
     * @return <code>true</code> if the URL was encoded
     */
    @Override
    public String encodeRedirectURL(String url) {
        if (isEncodeable(toAbsolute(url))) {
            return (toEncoded(url, request.getSessionInternal().getIdInternal()));
        } else {
            return (url);
        }
    }
로그인 후 복사

에만 중점을 둡니다. 메서드 설명은 명확하게 작성됩니다. 필요한 경우 리디렉션된 URL에 세션 ID를 삽입합니다. isEncodeable 메소드를 다시 살펴보겠습니다. 클라이언트 쿠키의 사용 가능 여부를 확인하기 위해 Request 객체의 isRequestedSessionIdFromCookie를 호출하는

/**
     * Return <code>true</code> if the specified URL should be encoded with
     * a session identifier.  This will be true if all of the following
     * conditions are met:
     * <ul>
     * <li>The request we are responding to asked for a valid session
     * <li>The requested session ID was not received via a cookie
     * <li>The specified URL points back to somewhere within the web
     *     application that is responding to this request
     * </ul>
     *
     * @param location Absolute URL to be validated
     * @return <code>true</code> if the URL should be encoded
     */
    protected boolean isEncodeable(final String location) {
        if (location == null) {
            return false;
        }
        // Is this an intra-document reference?
        if (location.startsWith("#")) {
            return false;
        }
        // Are we in a valid session that is not using cookies?
        final Request hreq = request;
        final Session session = hreq.getSessionInternal(false);
        if (session == null) {
            return false;
        }
        //这里其实就是网上说的客户端禁用Cookie
        if (hreq.isRequestedSessionIdFromCookie()) {
            return false;
        }
        // Is URL encoding permitted
        // servlet3.0后可以在项目web.xml里关掉URL重写,对应tomat7之后
        if (!hreq.getServletContext().getEffectiveSessionTrackingModes().
                contains(SessionTrackingMode.URL)) {
            return false;
        }
        if (SecurityUtil.isPackageProtectionEnabled()) {
            return (
                AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                @Override
                public Boolean run(){
                    return Boolean.valueOf(doIsEncodeable(hreq, session, location));
                }
            })).booleanValue();
        } else {
            //这个方法会重写URL
            return doIsEncodeable(hreq, session, location);
        }
    }
로그인 후 복사

에 중국어 주석을 추가했습니다. 요청에 JSESSIONID 쿠키가 전달되었는지 여부를 읽습니다. 그래서 인터넷에서 어떤 분들은 처음 방문하신다고 하십니다. 사실 클라이언트가 JSESSIONID를 전달하지 않는 한 Tomcat은 쿠키를 사용할 수 없는 것으로 가정합니다

위 내용은 jsessionid가 뭐야?의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

<gum> : Bubble Gum Simulator Infinity- 로얄 키를 얻고 사용하는 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Nordhold : Fusion System, 설명
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌
Mandragora : 마녀 트리의 속삭임 - Grappling Hook 잠금 해제 방법
3 몇 주 전 By 尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

메모장++7.3.1

메모장++7.3.1

사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전

SublimeText3 중국어 버전

중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경

드림위버 CS6

드림위버 CS6

시각적 웹 개발 도구

SublimeText3 Mac 버전

SublimeText3 Mac 버전

신 수준의 코드 편집 소프트웨어(SublimeText3)