在转发之前response.setCharacterEncoding("utf-8"); 试试!如果还是乱码,就清清浏览器缓存或者关闭浏览器,重启服务器再试应该没问题了。
解决方案 »
- hibernate的saveorupdate失效
- ehcache.xml异常。。。which is already used by an existing CacheManager.
- Strust配置文件详解!!!
- jsp中下拉列表框问题
- 有不有短信网关的达人在啊,请教SMPP协议的一些问题,在线等
- 在线等,load()异常,解决了一天了.....555555555555
- 诚聘java高级工程师,有意者请进
- There is no Action mapped for namespace [/] and action name [] associated with c
- 请问如何使用JAVA来调用扫描仪???
- 对于一个频繁增删的表,如何建立索引,提高查询效率?
- 用邮箱或用户名都可以实现登录 后台代码大概怎么写 用SSH?
- 关于java过滤器的问题。
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);
arraylist里的东西在servlet里显示都是正常的
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>
我用的doPost的方法,这有影响吗?
request.setAttribute("start_to_jsp",start_to_jsp);这一步都是没问题的啊。就是传到JSP后get出来就显示不出来了
<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>感觉和编码有关的该有的你都有了呃。
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>
可以过滤器。
还可以用new String(testString.getBytes(格式1),格式2)接收一下
格式1是原来的编码格式,格式2是你需要的编码格式。