服务器环境为linuxCookie cookies[] = request.getCookies();

   if (cookies != null){
        for(int i=0; i<cookies.length; i++) {
            if(cookies[i].getName().equals("city")) {
cityName =  cookies[i].getValue();
}
        }
    }<%=cityName%>就变成了"%u5317%u4E为什么呢?

解决方案 »

  1.   

    "%u5317%u4EAC"是“北京”的utf-8 编码你转码输出就好了
      

  2.   

    你用脚本执行这段代码看看: ^_^
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    alert(unescape("%u5317%u4EAC"));
    //-->
    </SCRIPT>
      

  3.   

    在往cookies中存之前   先把要存的东西
    java.net.URLEncoder.encode()一下
    读的时候在转过来。  encode前要注意程序本身的字符编码。
      

  4.   

    String username=new String(username.getBytes("ISO8859-1"),"GBK");
    System.out.println("username : "+username);
    一定是对的,今天我刚好碰到这个问题............................
      

  5.   

    <%@ page import="java.sql.*,java.net.*"%>
    //这样建立COOKIE,name为你要存的字符串
    Cookie cookie1=new Cookie("yourname","new String(java.net.URLEncoder.encode(name));
    -----------------------------------------------------------------------------------
    //读的时候
    new String(java.net.URLDecoder.decode(cookies[i].getValue()));
      

  6.   

    Cookie cookie1=new Cookie("yourname",new String(java.net.URLEncoder.encode(name));
    前面打错了
      

  7.   

    <2006-8-21 下午16时27分49秒 CST> <Error> <HTTP> <BEA-101019> <[ServletContext(id
    =31268562,name=web,context-path=/web)] Servlet failed with IOException
    weblogic.servlet.jsp.CompilationException: Compilation of D:\bea\user_projects\m
    ydomain\.\myserver\.wlnotdelete\extract\myserver_web_web\jsp_servlet\_test\__wri
    tecookie.java failed.
            at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:446)
            at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:220)
            at weblogic.servlet.jsp.JspStub.prepareServlet(JspStub.java:172)
            at weblogic.servlet.internal.ServletStubImpl.getServlet(ServletStubImpl.
    java:504)
            at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:349)
            at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
            at com.lxxx.common.utils.SetEncodingFilter.doFilter(SetEncodingFilter.ja
    va:61)
            at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.ja
    va:27)
            at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:6297)
            at weblogic.security.acl.internal.AuthenticatedSubject.doAs(Authenticate
    dSubject.java:317)
            at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:
    97)
            at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3575)
            at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2573)
            at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178)
            at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151)
    Caused by: java.io.IOException: Compiler failed executable.exec
            at weblogic.utils.compiler.CompilerInvoker.compileMaybeExit(CompilerInvo
    ker.java:505)
            at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:
    364)
            at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:
    372)
            at weblogic.utils.compiler.CompilerInvoker.compile(CompilerInvoker.java:
    357)
            at weblogic.servlet.jsp.JspStub.compilePage(JspStub.java:419)
            ... 15 more
    >