其他分享
首页 > 其他分享> > 会话技术Session特点

会话技术Session特点

作者:互联网

细节:

package com.ailyt.session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet(value = "/sessionStudy03")
public class SessionStudy03 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取Session
        HttpSession session = request.getSession();
        System.out.println(session);
        //期望客户端关闭后,Session也能相同
        Cookie cookie = new Cookie("JSESSIONID", session.getId());
        cookie.setMaxAge(60 * 60);
        response.addCookie(cookie);

    }
}

<session-config>
	<dession-timeout>30</dession-timeout>
</session-config>

Session的特点:

Session与Cookie的区别:

标签:session,特点,会话,Session,Cookie,关闭,import,response
来源: https://www.cnblogs.com/ailhy/p/16588556.html