The Cookie class of Java EE 6.0 already has the HttpOnly setting method.

Source: Internet
Author: User

Generally, cookies are obtained from the document object. Now, when setting cookies, the browser generally accepts a parameter called HttpOnly, which is the same as other parameters such as domain. Once this HttpOnly is set, you cannot see the Cookie in the document Object of the browser, and the browser will not be affected when browsing, because the Cookie will be sent out in the browser header (including when ajax is used ), applications generally do not operate on these sensitive cookies in js. For some sensitive cookies, we use HttpOnly. For some cookies that need to be operated in applications, we will not set them, this ensures the security of Cookie information and applications.
If you are using a container compatible with Java EE 6.0, such as Tomcat 7, the Cookie class already has the setHttpOnly method to use the HttpOnly Cookie attribute.
1 cookie. setHttpOnly (true );
The Cookie generated after setting will be added at the end; HttpOnly
In addition, if Session is used, the jsessionid Cookie can be used to enable HttpOnly by using useHttpOnly configuration in Context. For example:
1 <Context path = "" docBase = "D:/WORKDIR/oschina/webapp"
2 reloadable = "false" useHttpOnly = "true"/>
You can also configure the following in web. xml:
1 <session-config>
2 <cookie-config>
3 4 </cookie-config>
5 <session-config>
For. NET 2.0 applications, use the following configuration in the system. web/httpCookies element of web. config to enable HttpOnly:
1 The procedure is as follows:
C #:
1 HttpCookie myCookie = new HttpCookie ("myCookie ");
2 myCookie. HttpOnly = true;
3 Response. AppendCookie (myCookie );
VB. NET:
1 Dim myCookie As HttpCookie = new HttpCookie ("myCookie ")
2 myCookie. HttpOnly = True
3 Response. AppendCookie (myCookie)
. NET 1.1 can only be handled manually:
1 Response. Cookies [cookie]. Path + = "; HttpOnly ";
PHP has supported HttpOnly since version 5.2.0.
1 session. cookie_httponly = True
 

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.