今天在做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 错误的更多相关文章

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

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

  2. 【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 ...

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

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

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

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

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

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

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

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

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

随机推荐

  1. 如何在eclipse中添加ADT

    工具: Eclipse:官网下载地址:http://www.eclipse.org/downloads/下载SE或者EE版本的都可以 ADT:因为涉及到FQ问题,所以这里我给出一个参考网址:http: ...

  2. 使用python读取word,写入execl

    word里面有2张表,需要找到第二张表,并写入execl中: 代码如下: #coding:utf-8 import os from docx import Document import win32c ...

  3. (jQuery知识点整理-含有选择器)

                                       第一单元                                       jQuery介绍:   javaScript ...

  4. 笔记:MyBatis 其他特性

    多行结果集映射成Map 如果你有一个映射语句返回多行记录,并且你想以HashMap的形式存储记录的值,使用记录列名作为key值,而记录对应值或为value值.我们可以使用sqlSession.sele ...

  5. V-bind详细使用

    v-bind  主要用于属性绑定,Vue官方提供了一个简写方式 :bind,例如: <!-- 完整语法 --> <a v-bind:href="url">& ...

  6. 【Bootstrap】优秀小插件收集

    Bootstrap中不乏很多优秀的小插件来让界面更加漂亮.比如之前做过笔记的bootstrap-fileinput,select2,datetimepicker等都是属于这一系列的.这些相对而言比较大 ...

  7. 【Python】 hash值计算 hashlib & hmac

    hashlib & hmac *不是很清楚能不能把这种hash值取样算法称之为加密,但是似乎好像也是这么说的哈(非科班出身的野路子就是没这种基本知识的) ■ 基本用法 hashlib支持MD5 ...

  8. 数据库 --> MySQL使用

    MySQL使用 代码: #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>#includ ...

  9. Java多线程:synchronized关键字和Lock

    一.synchronized synchronized关键字可以用于声明方法,也可以用来声明代码块,下面分别看一下具体的场景(摘抄自<大型网站系统与Java中间件实践>) 案例一:其中fo ...

  10. 【Java实现】栈和队列就是这么简单

    一.前言 上一篇已经讲过了链表[Java实现单向链表]了,它跟数组都是线性结构的基础,本文主要讲解线性结构的应用:栈和队列 如果写错的地方希望大家能够多多体谅并指正哦,如果有更好的理解的方式也希望能够 ...