Javaweb Learning Record (15)--processing after a browser cookie is disabled

Source: Internet
Author: User

IE Disable cookie mode:

Example one:

Demo.do Related Codes

public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
HttpSession session=request.getsession ();
String Jsessionid=session.getid ();
Cookie Sessioncookie=new Cookie ("Jsessionid", Jsessionid);
Session.setattribute ("name", "zzz");
String Url=response.encoderedirecturl ("./demo2.do");
Response.sendredirect (URL);
}

Demo2.do Related Codes

public void doget (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
HttpSession session = Request.getsession ();

Gets the ID of the session
String jsessionid = Session.getid ();

System.out.println (Session.getattribute ("name"));
}

Enter Address Http://127.0.0.1:8080/cookie/demo.do

Results

Address bar Results:

http://127.0.0.1:8080/cookie/demo2.do;jsessionid=D2B0058380743E3731D50C49E6355144

HttpWatch results:

Console has output as zzz

Example two:

Demo.do Code

Response.setcontenttype ("Text/html;charset=utf-8");

PrintWriter out = Response.getwriter ();

Out.println ("Out.println ("<body>");
String Url=response.encodeurl ("./demo2.do");
Out.println ("<a href= './demo2.do ' > Add to Cart </a>");
Out.println ("<body>");
Out.println ("

Demo1.do related invariant

The result is similar to example one

Description

(a), and then disable the cookie should be used IP address access Http://172.16.237.247:8080/web_11/goods.do?oper=detailCart

(ii), ¨ shows the problem caused by servlet sharing data after disabling cookies. ¨ solution: URL rewrite response. Encoderedirecturl (java.lang.String URL)

Used to override the URL address after the Sendredirect method.

Response. Encodeurl (java.lang.String URL)

Used to override the URL address of the form action and hyperlink

¨ Add: Session expiration Web. xml file configuration session expiration time

Javaweb Learning Record (15)--processing after a browser cookie is disabled

Related Article

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.