Javaweb base session is only created when the first time it is acquired

Source: Internet
Author: User
Tags stub

Li Wu:
Good study and thinking, honouring teachers save Thanksgiving. Leaf See root three return to one, rivers the same oneness.
Meekness Conscience Lord, willing to do without regrets to the most bitter. Reading exercise strong body and mind, Prudential advised and the line and cherish.



Javaee:7
javase:1.8
jstl:1.2.2
Server:tomcat 8.5
Browser:chrome/firefox
Os:windows7 x64
Ide:myeclipse



Note:

The content of this post is correct, if not, to the most bitter not guarantee. Forget to add some key notes because you were careless in your record. Then, it is guaranteed that the session will only be created the first time it is acquired.

Havesessionidservlet.java

Package Com.jizuiku.servlet;import Java.io.ioexception;import Javax.servlet.requestdispatcher;import Javax.servlet.servletexception;import Javax.servlet.http.cookie;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import javax.servlet.http.httpsession;/** * * * @author Blog Park-to the most bitter * @version V2017.11.21 */public class Havesessionidservlet Exte NDS HttpServlet {@Overrideprotected void doget (httpservletrequest req, httpservletresponse response) throws Servletexception, IOException {//TODO auto-generated method stub//The server does not create a session immediately. Instead, the session is created when the session is first acquired. The importance of theoretical pass! Req.getsession (); get sessionreq.getsession ();//Handle Chinese Response.setcontenttype ("Text/html;charset=utf-8"); Response.getwriter (). Print ("with Jsessionid");} @Overrideprotected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {//TODO auto-generated method stub}}


Nosessionidservlet.java

Package Com.jizuiku.servlet;import Java.io.ioexception;import Javax.servlet.requestdispatcher;import Javax.servlet.servletexception;import Javax.servlet.http.cookie;import Javax.servlet.http.httpservlet;import Javax.servlet.http.httpservletrequest;import Javax.servlet.http.httpservletresponse;import javax.servlet.http.httpsession;/** * * *  @author Blog Park-to the most bitter * @version V2017.11.21 */public class Nosessionidservlet extends HttpServlet {@Overrideprotected void doget (HttpServletRequest req, httpservletresponse Response) throws Servletexception, IOException {//TODO auto-generated method stub//handle Chinese Response.setcontenttype ("text/ Html;charset=utf-8 "); Response.getwriter (). Print (" no Jsessionid ");} @Overrideprotected void DoPost (HttpServletRequest request, httpservletresponse response) throws Servletexception, IOException {//TODO auto-generated method stub}}

Browser for viewing

Close the browser, open the browser again to view

Learning resources: Itcast and Itheima Video library. If you have public resources, can share to me, with your resources to learn also can.
Blog post is to watch the video, into thinking written. It's good that the teacher speaks well. Blog bad, is to give the most bitter not serious.

Javaweb base session is only created when the first time it is acquired

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.