在转发之前response.setCharacterEncoding("utf-8"); 试试!如果还是乱码,就清清浏览器缓存或者关闭浏览器,重启服务器再试应该没问题了。

解决方案 »

  1.   

    你的start_to_jsp变量是一ArrayList????
      

  2.   

    页面编码是utf-8,请求和响应也设置为utf-8,这样应该可以了
    response.setCharacterEncoding("utf-8"); request.setCharacterEncoding("utf-8"); RequestDispatcher dis = request.getRequestDispatcher("navi_success.jsp");
    request.setAttribute("start_to_jsp",start_to_jsp);
    dis.forward(request, response);
      

  3.   

    加个字符过滤器看看,还有你的list里面的中文是正确的不
      

  4.   

    过滤器是我最早的策略,加完之后不行。
    arraylist里的东西在servlet里显示都是正常的
      

  5.   

    可以先将工程的字符编码设成GBK
      

  6.   

    可以试着把你tomcat编码也设置utf-8
      

  7.   

    好吧,闲着帮你测试了,我这里没有出问题啊。 你看哪里不同?
    public class MyServlet extends HttpServlet 
    {
    private static final long serialVersionUID = 1L; @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException 
    {
    List<String> list = new ArrayList<String>();

    list.add("tom");
    list.add("jim");
    list.add("marry");
    list.add("我爱你!");

    request.setAttribute("list", list);

    request.getRequestDispatcher("showlist.jsp").forward(request, response);
    }
    }
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%=request.getAttribute("list") %>
    </body>
    </html>
      

  8.   

    已经在server.xml里面改过了。不行
      

  9.   


    我用的doPost的方法,这有影响吗?
      

  10.   

    我用的doPost方法。这有影响吗?
      

  11.   

    doPost方法接受表单信息,doGet接收连接和地址栏直接输入。 没影响!
      

  12.   

    web.xml配置编码格式了吗?如果配置了,看看是不是UTF-8的
      

  13.   

    你debug一下 ,看看哪一步乱码了。
      

  14.   

    在servlet里面是完全没问题的。
    request.setAttribute("start_to_jsp",start_to_jsp);这一步都是没问题的啊。就是传到JSP后get出来就显示不出来了
      

  15.   


    <filter>
    <filter-name>encodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value> </init-param>
    </filter>感觉和编码有关的该有的你都有了呃。
      

  16.   

    System.out.println(Charset.defaultCharset()); 
      

  17.   

    楼主:不是编码问题import java.io.IOException;
    import java.util.ArrayList;
    import java.util.List;import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;public class myServlet1 extends HttpServlet
    {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
    {
    List<String> list=new ArrayList<String>();
    list.add("hello");
    list.add("world");
    list.add("我爱你");
    req.setAttribute("list", list);
    req.getRequestDispatcher("showList.jsp").forward(req, resp);
    }
    }showList.jsp:
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"> <title>My JSP 'showList.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    --> </head> <body>
    <%
    List<String> list = (List<String>) request.getAttribute("list");
    %>
    <%
    for (String s : list)
    {
    %>
    <li><%=s %></li><br>
    <%
    }
    %>
    </body>
    </html>
      

  18.   

    在你的eclipse   项目 ->  右键   -> Properties -> Resource 对话框中Text file encoding 选择other 再选择UTF-8如果本来就是UTF-8就不用改了。 如果不是 , 就要改 ,改了以后可能你的一些文件都会出现乱码 ,你再修改一下就行了。
      

  19.   

    2楼的试试
    可以过滤器。
    还可以用new String(testString.getBytes(格式1),格式2)接收一下
    格式1是原来的编码格式,格式2是你需要的编码格式。