QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 1497|回复: 0

JSP写中文cookie

[复制链接]
发表于 2004-2-29 20:09:00 | 显示全部楼层 |阅读模式
写cookie的代码!
<%@ page contentType = "text/html;charset=gb2312"%>
<%@ page language = "java"%>
<%@ page import= "java.net.*"%>
<%
String gbstring = "请教再虚拟主机中是如何配置";
String testCookie = new String(URLEncoder.encode(gbstring, "UTF-8"));
Cookie newcookie3 = new Cookie("firstcooki",testCookie);
newcookie3.setMaxAge(100);
response.addCookie(newcookie3);
%>



以下是cookie读取代码:
<%@ page contentType = "text/html;charset=gb2312"%>
<%@ page language = "java"%>
<%@ page import= "java.net.*"%>
<html>
<body>
&lt;%
Cookie cookies[]=request.getCookies();
Cookie sCookie=null;
String svalue=null;
String sname=null;
for(int ii=0;ii&lt;cookies.length;ii++)
{
     sCookie=cookies[ii];
     sname=sCookie.getName();
     svalue=URLDecoder.decode(sCookie.getValue(), "UTF-8");
     svalue=new String(svalue.getBytes("8859_1", "gb2312");
     out.println(svalue+"/"+sname);
}
%&gt;
</body>
&lt;/html&gt;
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-8 22:35 , Processed in 0.051915 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表