Servlets & JSP Series 6 - Conversational state
-
An HttpSession object can hold conversational state across multiple requests from the same client, in orther words it persists for an entire session with a specific client, we can use it to store everything we get back from the client in all the request the client makes during a session.
-
On the client’s first request, the Container generates a unique session ID and gives it back to the client with the response, the client sends back the session ID with each subsequent request, the container sees the ID, finds the matching session, and associates the session with the request.
-
The container has to get the sesseion ID to the client as part of the response, and the client has to send back the session ID as part of the request, the simplest and most common way to exchange the info is through cookies.
-
If the client won’t take cookies, we can use URL rewriting as a back-up. URL rewriting is automatic, but only if you encode your URLs, you have to run all your URLs through a method of the response object-encodeURL() or encodeRedirectURL()-and the container does everything else. URL encoding is all about the response.
-
URL rewriting adds the session ID to the end of the URLs in the HTML that you write to the response; The seesion ID then comes back with the request as “extra” info at the end of the request URL; URL rewriting will happen automatically if cookies don’t work with the client, but you have to explicitly encode all of the URLs you write; To encode a URL, call response.encodeURL(aString); There’s no way to get automatic URL rewriting with your static pages, so if you depend on sessions, you must use dynamically-generated pages.
-
Three ways a session can be got rid of stale sessions: 1.It times out; 2.You call invalidate*( on the session object; 3.The application goes down.
-
Specify timeouts in the DD using MINUTES, but if we set a timeout programmatically, we speciy SECONDS.
-
We can use cookies to exchange name/value String pairs between the server and the client, the servlet sends the cookie to the client, and the client sends it back with each subsequent request, session cookies vanish when the client’s browser quits, but you can tell a cookie to persist on the client even after the browser shuts down.
-
Only HttpSession objects move from the VM to another, there is one servletcontext per VM, there is one ServletConfig per servlet, per VM, but there is only one HttpSession object for a given seesion ID per web app, regardless of how many VM’s the app is distributed across.
-
Each servlet has its own ServletConfig, and both servlet in the web app share a ServletContext, everything except the HttpSession is duplicated on the other VM, everything is duplicated in the second server except the HttpSession objects, sessions live in only one place at any given moment, the same session ID for a given web app will never appear in two VMs at the same time.
-
If you need to save and restore instance variable state in your attrivute, use HttpSessionActivationListener, and use the two event callback(sessionDidActivate() and sessionWillPassivate()) the way(This is serialization) you’d use readObject() and writeObjest().
相关推荐
Head First Servlets&JSP;-第2版-高清扫描版-带详细书签 高清扫描版,书签比较详细,和目录一样
深入浅出Servlets&JSP,感兴趣的人看一下吧
Head First Servlets & JSP(完好高清中文版)2.pdf 深入浅出 Servlets & JSP(完好高清中文版)2.pdf
《Head First Servlets & JSP》是一本广受欢迎的教材,它深入浅出地讲解了这些概念,帮助开发者通过SCWCD(Sun Certified Web Component Developer)认证。以下是一些关键知识点的详细解释: 1. **Servlet**: - *...
Head First Servlets & JSP 完好高清中文版 part3 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。
【标题】"jstl&standard&jsp-api&servlet-api.jar" 涉及到的是四个关键的Java Web开发库,它们在构建基于Java的Web应用程序时起着至关重要的作用。这里,我们主要讨论JSTL(JavaServer Pages Standard Tag Library)...
6. MVC(Model-View-Controller)模式:理解如何在Servlets和JSP中应用MVC设计模式,实现业务逻辑与视图的解耦。 7. 用户会话管理:探讨session对象的使用,以及如何实现基于会话的用户跟踪。 8. 请求转发与重定向:...
《Head First Servlets & JSP, Second Edition》是一本针对初学者的优秀教材,它深入浅出地介绍了Servlet和JSP这两个Java Web开发的核心技术。Servlet是Java平台上的服务器端编程接口,而JSP(JavaServer Pages)则...
Head First Servlets & JSP(完好高清中文版)1.pdf 深入浅出 Servlets & JSP(完好高清中文版)1.pdf
Head First Servlets & JSP 完好高清中文版 part6 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。
head first servlets & JSP(3)
head first servlets & JSP(2)
《Head First Servlets&JSP》应了最新的学习理论,能将知识直接送到你的大脑里。你会通过不寻常的方式同Servlet和JSP打交道,可以学得更深入、更快,而且更重要的是,你能真正地学以致用。你可以看看为什么那么多...
Head First Servlets & JSP 完好高清中文版 part1 共6部分 Head First系列的书绝对是初学者的首选!风格生动有趣,讲解由浅入深。 发现网上流传的中文版存在有几处部分页面缺失的问题,花一个下午进行了修复。
Head First Servlets & JSP 高清中文版 part2 共5部分
Java Servlets 和 JSP(JavaServer Pages)是Java在Web开发中的两个核心技术,它们用于构建动态、交互式的网页应用程序。本教程将深入讲解这两个概念及其优势、安装配置、基本使用方法,以及如何处理请求和响应。 1...
《Java开发指南Servlets&JSP》是一本深入讲解Java Web开发的重要书籍,主要涵盖了Servlets和JSP(JavaServer Pages)这两个核心技术。在Java Web开发领域,Servlets和JSP是构建动态网站和Web应用程序的基础,它们为...
《Core Servlets & JSP_cn》是一本专为Java初学者设计的教程,全面涵盖了Servlets和JSP(JavaServer Pages)的核心技术。Servlets是Java Web开发中的基础组件,用于处理HTTP请求并生成动态响应,而JSP则是用于创建...
《Head First Servlets & JSP》是一本深受程序员喜爱的学习指南,主要涵盖了Servlets和JSP(JavaServer Pages)这两个核心的Java Web开发技术。Servlets是Java平台上的服务器端编程模型,而JSP则是用于创建动态网页...