System.err.println(request.getSession()+"======登录session====");
System.err.println(request.getServerName()+"=====运行的服务器");
System.err.println(request.getServletPath()+"=====请求路径");
System.err.println(request.getServletContext()+"=====运行背景");
System.err.println(request.getHeader("Cookie")+"=====请求Cookie");
Cookie[] cookie=request.getCookies();
for (Cookie cookie2 : cookie) {
System.err.println(cookie2+"cookies数组");
System.err.println(cookie2.getValue()+"====cookie值");
cookie2.setValue("123456789");
System.err.println(cookie2.getValue()+"====cookie值");
response.addCookie(cookie2);
System.err.println(response.getHeader("Set-Cookie"));
}
HttpSession session = request.getSession();
session.setAttribute("key", "value");
System.err.println(session.getAttribute("key")+"--------");
查看session内容
HttpSession session = request.getSession( false );
String serviceType = ( String ) session.getAttribute( "serviceType" );
System.err.println(session);
// 获取session中所有的键值
Enumeration<String> attrs = session.getAttributeNames();
// 遍历attrs中的
while(attrs.hasMoreElements()){
// 获取session键值
String name = attrs.nextElement().toString();
// 根据键值取session中的值
Object vakue = session.getAttribute(name);
// 打印结果
System.out.println(name + ":" + vakue +"\n");}