An invalid character [32] was present in the Cookie value 错误
今天在做cookie部分的demo的时候出现了一个错误Servlet部分的代码如下
Date data=new Date();
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String Last = format.format(data);
// System.out.println(Last); Cookie cookie =new Cookie("Lastname",Last);
cookie.setMaxAge(60*10*500);
response.addCookie(cookie);
//获得用户携带的cookie
String last=null;
Cookie[] cookies = request.getCookies();
if(cookies!=null){
for(Cookie coo:cookies){
if("Lastname".equals(coo.getName())){
last = coo.getValue(); }
}
} response.setContentType("text/html;charset=utf-8");
if(last==null){ response.getWriter().write("您是第一次访问");
}else{
response.getWriter().write("你上次访问的时间为"+last);
}
再访问该Servlet的时候页面就为500,并报异常An invalid character [32] was present in the Cookie value,
后来发现32对应的编码是空格,后来发现
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");代码中产生了空格,后改为
SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd-hh:mm:ss");就可正常访问了
An invalid character [32] was present in the Cookie value 错误的更多相关文章
- An invalid character [32] was present in the Cookie value
系统安装Tomcat版本为:tomcat8,登录时报错"An invalid character [32] was present in the Cookie value" 处理方 ...
- 【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 va ...
- 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中Cookie使用问题(message:invalid character [32] was present in the Cookie value)
1. 问题描述 Servlet中执行下面一段代码: public void doGet(HttpServletRequest request, HttpServletResponse response ...
- 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 ...
- 【Tomcat】Invalid character found in the request target
Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC ...
- Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC
解决Invalid character found in the request target. The valid characters are defined in RFC 7230 and RF ...
- Tomcat : Invalid character found in the request target
Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC ...
随机推荐
- Sql中根据旧表创建新表的SQL语句
今天在网上查了下,根据旧表创建新表的SQL语句,网上给了两个答案 create table tab_new like tab_old (使用旧表创建新表) create table tab_new a ...
- js正则《转载收藏》
\:转义字符.'\\n'匹配\n ^:开始位置.'^[0-9]'匹配以数字开头的字符,可以匹配'88DC',不可匹配'DC88' $:结束位置.'[0-9]$'匹配以数字结尾的字符,可以匹配'ab12 ...
- 分享基于Qt5开发的一款故障波形模拟软件
背景介绍 这是一款采用Qt5编写的用于生成故障模拟波形的软件.生成的波形数据用于下发到终端机器生成对应的故障类型,用于培训相关设备维护人员的故障排查技能.因此,在这款软件中实现了故障方案管理.故障波形 ...
- 13.HashMap TreeMap HashTable LinkedHashMap 的区别
数据库基本连接equals和hashCode详解 http://www.cnblogs.com/XMMDMW/p/6502355.html
- 【Flask】 网站的用户管理
网站用户管理 不知道为什么很多学习Flask的人都是从搭博客开始的(大概是因为那本书的案例是博客,同时对bootstrap支持良好,bootstrap又是twitter开发的吧..)既然是搭建博客,就 ...
- 控制input只能输入数字和两位小数
<input type="text" name="je" onkeyup="clearNoNum(this)" /> funct ...
- Redis --> Redis架构设计
Redis架构设计 一.前言 Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库.缓存和消息中间件. 它支持多种类型的数据结构,如 字符串(strings), 散列 ...
- 理解HDFS
综述 当数据集的大小超过一台独立的物理计算机的存储能力时,就有必要对它进行分区并存储到若干台单独的计算机上.HDFS是hadoop的主要分布式存储系统,一个HDFS集群主要包括NameNode用来管理 ...
- java并发编程基础 --- 7章节 java中的13个原子操作类
当程序更新一个变量时,如果多线程同时更新这个变量,可能得到期望之外的值,比如变量 i=1,A线程更新 i+1,B线程也更新 I+1,经过两个线程的操作之后可能 I不等于3,而是等于2.因为A和B线程更 ...
- spring boot 1.x.x 到 spring boot 2.x.x 的那些变化
spring boot1 到 spring boot2的配置变化很大,迁移项目到spring boot2过程中发现以下变化 1.java 的 redis 配置添加了属性jedis 旧版 spring: ...