How to use cookies in Web Applications

Source: Internet
Author: User

Q:I want to add a cookie to an actionitem, and then sendredirect to another actionitem to verify the cookie. If there is a cookie, a page is displayed; otherwise, a response is returned. However, after adding a cookie, if sendredirect is enabled, the other actionitem cannot obtain the cookie value (indicating that the cookie is not successfully added). If not, sendredirect is response. content: = 'content of a certain page'. Then, you can click link to another actionitem to read the cookie.

A:Cookie is the header of a response and must be set before the body. If sendredirect is used, only the new page will be sent. The response set before sendredirect will be canceled. As a result, the cookie cannot be added to the header of the new page. Therefore, the cookie setting is unsuccessful! Solution: Never use sendredirect after setting the cookie. The problem you mentioned can be solved as follows: You can add code in HTML to automatically go to another page. We can write in the onaction event of webactionitem:

Response. Content: = '<meta HTTP-EQUIV = "refresh" content = "1;' +

'Url = http: // Chen/dll/chat/chatmain.exe/qtchat "> '+

'<P> </P> <p align = "center"> your reply has been added to the Forum' +

'<Br> two seconds later, return to the Forum homepage </P> ';

The URL is automatically returned.

 

Q:I first set a value in the cookie and then want to modify it. What should I do?

A:First, delete the value in the original cookie by setting the Cookie's expires to the earlier time and then setting it. For example:

// Delete the records in the original cookie

With response. Cookies. Add do begin

Name: = 'nickname ';

Value: = request. contentfields. Values ['nickname'];

Secure: = false;

Expires: = now-1;

End;

 

// Use the registered user name as the content in the cookie

With response. Cookies. Add do begin

Name: = 'nickname ';

Value: = request. contentfields. Values ['nickname'];

Secure: = false;

Expires: = now + 100;

End;

 

Q:How do I save temporary information through cookies? Like some forums, during a single browsing process. When you speak for the first time, you need to enter the password. When you browse again, you still need to enter the password, which is convenient and secure.

A:To set such a cookie, do not set expires. For example:

// Set temporary cookies

With response. Cookies. Add do begin

Name: = 'temppassword ';

Value: = spassword;

End;

 

In addition, we can also download some special controls for setting and reading cookies. These controls support adding ASP-like session functions to Web applications. Yes: http://codecentral.borland.com/

Www.applevb.com

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.