创建时间: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的更多相关文章

  1. cookie实例---显示上一次访问的时间与java.lang.IllegalArgumentException: An invalid character [32] was present in the Cookie value

    创建Cookie,名为lasttime,值为当前时间,添加到response中: 在A.jsp中获取请求中名为lasttime的Cookie: 如果不存在输出“您是第一次访问本站”,如果存在输出“您上 ...

  2. 异常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 ...

  3. 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 ...

  4. java中Cookie使用问题(message:invalid character [32] was present in the Cookie value)

    1. 问题描述 Servlet中执行下面一段代码: public void doGet(HttpServletRequest request, HttpServletResponse response ...

  5. An invalid character [32] was present in the Cookie value

    系统安装Tomcat版本为:tomcat8,登录时报错"An invalid character [32] was present in the Cookie value" 处理方 ...

  6. An invalid character [32] was present in the Cookie value 错误

    今天在做cookie部分的demo的时候出现了一个错误Servlet部分的代码如下 Date data=new Date(); SimpleDateFormat format=new SimpleDa ...

  7. 【URLDecoder】java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in es

    Java调用 URLDecoder.decode(str, "UTF-8"); 抛出以上的异常,其主要原因是% 在URL中是特殊字符,需要特殊转义一下, 上面的字符串中'%'是一个 ...

  8. 【myBatis】java.lang.IllegalArgumentException: No enum constant org.apache.ibatis.type.JdbcType.NUMBE

    可能#{current_date, jdbcType=VARCHAR}中的VARCHAR类型不对

  9. java.lang.IllegalArgumentException: An invalid domain [.test.com] was specified for this cookie解决方法

    当项目中使用单点登录功能时,通常会使用cookie进行信息的保存,这样就可以在多个子域名上存取用户信息. 比如有三个domain分别为test.com,cml.test.com,b.test.com这 ...

随机推荐

  1. 2.第一个Vue程序

    1.IDEA中安装Vue.js插件 2.建立项目以及html文件 1.创建一个 HTML 文件 2.引入 Vue.js <script src="https://cdn.jsdeliv ...

  2. ESA2GJK1DH1K升级篇: 快速的移植升级程序到自己的项目(BootLoader程序制作)

    前言 此代码兼容STM32F103全系列 为避免添加上升级程序造成内存不足,请使用128KB Flash及其以上的型号 这篇文章是为了能够让大家快速移植我的升级模板程序到自己的项目 BootLoade ...

  3. Tomcat服务部署与Nginx负载均衡配置

    一.中间键产品介绍 目前来说IBM的WebSphere,Oracle的Weblogic占据了市场上java语言Web站点的部分份额,该两种软件都是商业化的软件,由于性能优越,可靠性高等优点应用于大型互 ...

  4. [ Python入门教程 ] Python文件基本操作

    本文将python文件操作实例进行整理,以便后续取用. 文件打开和创建 Python中使用open()函数打开或创建文件.open()的声明如下: open(name[, mode[, bufferi ...

  5. [LeetCode] 895. Maximum Frequency Stack 最大频率栈

    Implement FreqStack, a class which simulates the operation of a stack-like data structure. FreqStack ...

  6. Go Windows 环境安装及配置(一)

    首先安装windows的包 go1.12.6.windows-amd64.msi cmd 查看下环境变量 go env set GOARCH=amd64 --架构 amd64/arm set GOBI ...

  7. Java一个简单的重试工具包

    在接口调用中由于各种原因,可能会重置失败的任务,使用Guava-Retrying可以方便的实现重试功能. 首先,需要引用Guava-Retrying的包 <dependency> < ...

  8. Unity Shader 屏幕后效果——高斯模糊

    高斯模糊是图像模糊处理中非常经典和常见的一种算法,也是Bloom屏幕效果的基础. 实现高斯模糊同样用到了卷积的概念,关于卷积的概念和原理详见我的另一篇博客: https://www.cnblogs.c ...

  9. 【开源监控】Grafana介绍与安装

    Grafana介绍与安装 Grafana介绍 场景:由于业务场景,有多个组织机构.需要在某个组织结构下,完成对本机构下的系统的实时监控以及可视化展示.底层已经用zabbix对监控指标做了数据的采集. ...

  10. 《Game Programming Patterns》游戏设计模式

    转载自:https://blog.csdn.net/poem_qianmo/article/details/52505170 https://blog.csdn.net/poem_qianmo/art ...