简体   繁体   English

在同一页面中检索Cookie

[英]Retrieving cookie in the same page

I have index.jsp page in which I have two input fields for two numbers to perform calculation. 我有index.jsp页,其中有两个数字的两个输入字段以执行计算。 I have 4 buttons for ADD,SUBTRACT,MULTIPLY and DIVIDE. 我有4个按钮用于添加,减,乘和除。 When I click on ADD button, it will go to servlet named Calculate.java and calculate the result and set the cookies. 当我单击ADD按钮时,它将转到名为Calculate.java的servlet并计算结果并设置cookie。 Now when I open index page, I want to display history of all previous calculations in index.jsp using cookies already set. 现在,当我打开索引页面时,我想使用已设置的cookie在index.jsp中显示以前所有计算的历史记录。 How to do that? 怎么做?

使用cookie是一个坏主意,请改用encodeUrl()。原因是并非所有浏览器都支持cookie,这意味着如果用户阻止了cookie,则您的代码将无法正常工作。但是在encodeUrl()的情况下,即使浏览器具有禁用的cookie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM