【Cookie】java.lang.IllegalArgumentException An invalid character [32] was present in the Cookie value
创建时间:6.30 java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value

报错原因:
Tomcat 8.5版本,在cookie值中不能使用空格。
代码:
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { Date date = new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String currentTime = format.format(date); Cookie accessTime = new Cookie("lastAccessTime",currentTime);
accessTime.setMaxAge(60*50);
response.addCookie(accessTime); String lastAccessTime=null;
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for(Cookie cookie:cookies) {
if(cookie.getName().equals("laseAccessTime")) {
lastAccessTime=cookie.getValue();
}
}
} if(lastAccessTime==null) {
response.setContentType("text/html;charset=UTF-8");
response.getWriter().write("您是第一次访问");
System.out.println(lastAccessTime);
}
else {
response.getWriter().write("您上次访问的时间是:"+lastAccessTime);
} }
问题出在这里:日期格式有空格,换成/即可

【Cookie】java.lang.IllegalArgumentException An invalid character [32] was present in the Cookie value的更多相关文章
- cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
创建Cookie,名为lasttime,值为当前时间,添加到response中: 在A.jsp中获取请求中名为lasttime的Cookie: 如果不存在输出“您是第一次访问本站”,如果存在输出“您上 ...
- 异常java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value
通过HttpServletResponse的addCookie(Cookie cookie)向客户端写cookie信息,这里使用的tomcat版本是8.5.31,出现如下报错: java.lang.I ...
- java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value
java.lang.IllegalArgumentException: An invalid character [34] was present in the Cookie value at org ...
- java中Cookie使用问题(message:invalid character [32] was present in the Cookie value)
1. 问题描述 Servlet中执行下面一段代码: public void doGet(HttpServletRequest request, HttpServletResponse response ...
- An invalid character [32] was present in the Cookie value
系统安装Tomcat版本为:tomcat8,登录时报错"An invalid character [32] was present in the Cookie value" 处理方 ...
- An invalid character [32] was present in the Cookie value 错误
今天在做cookie部分的demo的时候出现了一个错误Servlet部分的代码如下 Date data=new Date(); SimpleDateFormat format=new SimpleDa ...
- 【URLDecoder】java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in es
Java调用 URLDecoder.decode(str, "UTF-8"); 抛出以上的异常,其主要原因是% 在URL中是特殊字符,需要特殊转义一下, 上面的字符串中'%'是一个 ...
- 【myBatis】java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBE
可能#{current_date, jdbcType=VARCHAR}中的VARCHAR类型不对
- java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie解决方法
当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名上存取用户信息. 比如有三个domain分别为test.com,cml.test.com,b.test.com这 ...
随机推荐
- Function.prototype.call.bind
在JavaScript中借用方法 在JavaScript中,有时候需要在一个不同的对象上重用一个函数,而不是在定义它的对象或者原型中.通过使用call(),applay()和bind(),我们可以很方 ...
- [LeetCode] 843. Guess the Word 猜单词
This problem is an interactive problem new to the LeetCode platform. We are given a word list of uni ...
- [LeetCode] 871. Minimum Number of Refueling Stops 最少的加油站个数
A car travels from a starting position to a destination which is target miles east of the starting p ...
- [LeetCode] 314. Binary Tree Vertical Order Traversal 二叉树的竖直遍历
Given a binary tree, return the vertical order traversal of its nodes' values. (ie, from top to bott ...
- 小i机器人
//机器人回复 function xiaoirobot($openid, $content) { //定义app $app_key = ""; $app_secret = &quo ...
- 动手学深度学习5-softmax回归
softmax回归 softmax 回归模型 单样本分类的矢量计算表达式 小批量样本分类的矢量计算表达式 交叉熵损失函数 模型预测以及评价 小结 softmax回归 前几节介绍的是线性回归模型适用于输 ...
- 【转】Python入门:Anaconda和Pycharm的安装和配置
子曰:“工欲善其事,必先利其器.”学习Python就需要有编译Python程序的软件,一般情况下,我们选择在Python官网下载对应版本的Python然后用记事本编写,再在终端进行编译运行即可,但是对 ...
- Mysql系列(十二)—— 索引下推优化
索引条件下推(ICP)是对MySQL使用索引从表中检索行的情况的优化.如果没有ICP,存储引擎会遍历索引以查找基表中的行,并将它们返回给MySQL服务器,该服务器会评估WHERE行的条件.启用ICP后 ...
- 【02】Kubernets:使用 kubeadm 部署 K8S 集群
写在前面的话 通过上一节,知道了 K8S 有 Master / Node 组成,但是具体怎么个组成法,就是这一节具体谈的内容.概念性的东西我们会尽量以实验的形式将其复现. 部署 K8S 集群 互联网常 ...
- 关于YII框架Response content must not be an array的解决方法
public function actionGet_permissions() { \Yii::$app->response->format = \yii\web\Response::FO ...