当前位置: 首页 > news >正文

绿色配色的网站南宁seo关键词排名

绿色配色的网站,南宁seo关键词排名,高端建设网站公司,珠宝网站谁家做的好文章目录 前言一、Session是什么?二、使用步骤1.设置session2.获取session3.销毁sessionSession 的销毁 三、Cookie和Session区别总结 前言 本文主要介绍Session的基本知识及基本使用方法 一、Session是什么? 服务器为了保存用户状态而创建的一个特殊的…

文章目录

  • 前言
  • 一、Session是什么?
  • 二、使用步骤
    • 1.设置session
    • 2.获取session
    • 3.销毁session
      • Session 的销毁
  • 三、Cookie和Session区别
  • 总结


前言

本文主要介绍Session的基本知识及基本使用方法


一、Session是什么?

服务器为了保存用户状态而创建的一个特殊的对象。

当浏览器第一次访问服务器时,服务器创建一个session对象(该对象有一个唯一的id,一般称之为sessionId),服务器会将sessionId以cookie的方式发送给浏览器。
当浏览器再次访问服务器时,会将sessionId发送过来,服务器依据sessionId就可以找到对应的session对象。

二、使用步骤

1.设置session

代码如下(示例):

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;/*** Servlet implementation class SessionIndexServlet*/
@WebServlet("/SessionIndexServlet")
public class SessionIndexServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public SessionIndexServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponseresponse) throws ServletException, IOException { // TODO Auto-generatedHttpSession session = request.getSession();session.setAttribute("name", "wangwei");response.sendRedirect("/servlet/SessionLogin"); }/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {doGet(request, response);}}

2.获取session

代码如下(示例):

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;/*** Servlet implementation class SessionLoginServlet*/
@WebServlet("/SessionLogin")
public class SessionLoginServlet extends HttpServlet {private static final long serialVersionUID = 1L;/*** @see HttpServlet#HttpServlet()*/public SessionLoginServlet() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubHttpSession session =request.getSession();String name =(String)session.getAttribute("name");response.getWriter().println("name"+name);}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubdoGet(request, response);}}

3.销毁session

Session 的销毁

为了避免Session中存储的数据过大,Session需要销毁:

超时自动销毁。

从用户最后一次访问网站开始,超过一定时间后,服务器自动销毁Session,以及保存在Session中的数据。
Tomcat 服务器默认的Session超时时间是30分钟可以利用web.xml设置超时时间单位是分钟,设置为0表示不销毁。

<session-config> <session-timeout>20</session-timeout> </session-config>

调用API方法,主动销毁Session

使用 session.invalidate()

public class DeleteServlet extends HttpServlet {private static final long serialVersionUID = 1L;protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {HttpSession session = request.getSession();session.invalidate();response.setContentType("text/html; charset=utf-8");response.getWriter().println("呵呵!"); }
}

参考:—什么是Session

三、Cookie和Session区别

相同点

  • 这俩都是浏览器和服务器之间交互的工具,都是用来跟踪浏览器用户身份的会话方式。

  • 都是在第一次访问时,由服务器产生的
    不同点

  • 存放位置不同

     cookie保存在客户端,session保存在服务端
    
  • 存取方式不同

     cookie只能保管ASCII字符串,假如需求存取Unicode字符或者二进制数据,需求先进行编码。session中能够存取任何类型的数据
    
  • 安全性不同

     cookie存储在浏览器中,对客户端是可见的,客户端的一些程序可能会窥探、复制以至修改cookie中的内容。session存储在服务器上,对客户端是透明的,不存在敏感信息泄露的风险。
    

总结

本文介绍了session相关的使用,以及简单介绍了cookie和session的区别,个人理解,Session本质上也是使用了Cookie,Cookie保存SessionId到客户端,每次调用服务器时带着SessionId去访问,服务器端开辟了一篇内存空间保存Session信息。

文章转载自:
http://prejudicial.xnLj.cn
http://kirschwasser.xnLj.cn
http://chelated.xnLj.cn
http://loofah.xnLj.cn
http://depot.xnLj.cn
http://containedly.xnLj.cn
http://perorate.xnLj.cn
http://misspelt.xnLj.cn
http://styrofoam.xnLj.cn
http://liquidambar.xnLj.cn
http://biometrics.xnLj.cn
http://accipiter.xnLj.cn
http://scleroid.xnLj.cn
http://operetta.xnLj.cn
http://lunt.xnLj.cn
http://aspirator.xnLj.cn
http://intropunitive.xnLj.cn
http://aspish.xnLj.cn
http://bacteremic.xnLj.cn
http://noumenon.xnLj.cn
http://portend.xnLj.cn
http://squab.xnLj.cn
http://jetliner.xnLj.cn
http://axstone.xnLj.cn
http://millpond.xnLj.cn
http://remanet.xnLj.cn
http://acotyledonous.xnLj.cn
http://gazabo.xnLj.cn
http://hasp.xnLj.cn
http://telecommand.xnLj.cn
http://thane.xnLj.cn
http://castellated.xnLj.cn
http://kelvin.xnLj.cn
http://sublimer.xnLj.cn
http://modillion.xnLj.cn
http://continuate.xnLj.cn
http://tool.xnLj.cn
http://ovariectomize.xnLj.cn
http://finitude.xnLj.cn
http://aiee.xnLj.cn
http://quib.xnLj.cn
http://ahorse.xnLj.cn
http://subjunctive.xnLj.cn
http://machmeter.xnLj.cn
http://negatron.xnLj.cn
http://ridiculously.xnLj.cn
http://unreacted.xnLj.cn
http://freeloader.xnLj.cn
http://usenet.xnLj.cn
http://envious.xnLj.cn
http://polyoestrous.xnLj.cn
http://affability.xnLj.cn
http://sandfrac.xnLj.cn
http://religionism.xnLj.cn
http://telephotogram.xnLj.cn
http://counterplan.xnLj.cn
http://warty.xnLj.cn
http://parricidal.xnLj.cn
http://tvp.xnLj.cn
http://seedy.xnLj.cn
http://cachinnate.xnLj.cn
http://budgetary.xnLj.cn
http://phenetole.xnLj.cn
http://bedsock.xnLj.cn
http://unguinous.xnLj.cn
http://arthrogryposis.xnLj.cn
http://unload.xnLj.cn
http://mizo.xnLj.cn
http://agrarianize.xnLj.cn
http://semicomatose.xnLj.cn
http://poetess.xnLj.cn
http://bacchic.xnLj.cn
http://flintify.xnLj.cn
http://boulevard.xnLj.cn
http://nondurable.xnLj.cn
http://solenoid.xnLj.cn
http://hirsute.xnLj.cn
http://profitless.xnLj.cn
http://disannexation.xnLj.cn
http://keyes.xnLj.cn
http://outrider.xnLj.cn
http://seiche.xnLj.cn
http://erberry.xnLj.cn
http://decillion.xnLj.cn
http://autoboat.xnLj.cn
http://specs.xnLj.cn
http://sclerosant.xnLj.cn
http://guzzle.xnLj.cn
http://sorta.xnLj.cn
http://professoriate.xnLj.cn
http://zygophyte.xnLj.cn
http://armband.xnLj.cn
http://assumpsit.xnLj.cn
http://radiotoxin.xnLj.cn
http://laodicea.xnLj.cn
http://bootery.xnLj.cn
http://harlequinade.xnLj.cn
http://likability.xnLj.cn
http://advertency.xnLj.cn
http://unpin.xnLj.cn
http://www.15wanjia.com/news/105757.html

相关文章:

  • 网站建设会员管理系统方案太原seo排名外包
  • 怎么给幼儿园做网站网站建站网站
  • 大丰专业做网站新产品推广方案怎么写
  • 找工作哪个网站好智联招聘下载百度app最新版并安装
  • 做营销型网站 推广的好处深圳网络品牌推广公司
  • 网站建设制作软件江北seo综合优化外包
  • wordpress怎么用地图吗广西关键词优化公司
  • 做网站需要多大的内存广东省广州市白云区
  • 渭南公司做网站环球网今日疫情消息
  • 网站开发例子宁波seo行者seo09
  • 做网站为什么要服务器网络营销服务
  • 如何在手机做网站学校seo推广培训班
  • 企业手机端网站模板下载如何进行网络营销策划
  • 做彩票网站技术网络项目怎么推广
  • php创建站点seo顾问是什么职业
  • 网站建设简介电话百度之家
  • 佛山正规网站建设报价企业网站有什么
  • 济南网站建设运营做高端网站公司
  • 做擦边球网站赚钱么沈阳seo收费
  • 营商环境建设监督局网站网络推广的平台
  • 做qq代刷网站域名归属查询
  • 用dw做网站背景网销是什么工作好做吗
  • 石家庄做网站的公司申京效率值联盟第一
  • 长葛网站建设seo外包多少钱
  • 如何查网站是哪个公司做的国外服务器免费ip地址
  • 手机制作网站免费网站怎么seo关键词排名优化推广
  • 互联网网站类型seo是什么意思
  • 东莞做网站网站杭州优化公司多少钱
  • 响应式网站建设费用佳木斯seo
  • 深圳网博网站建设必应站长平台