我现有两个页面
a.jsp里面的编码是utf-8的,因为a.jsp的编码由于特殊需要只能是utf-8的
<%@ page contentType="text/html;charset=UTF-8"%>//是utf-8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
在form里有一些文本框及下拉框
<form name="frmItem" action="./DoLogin.jsp" method="<%=IA_TJFS%>">
....
</form>当在a.jsp页面的文本框里输入汉字后,点提交按钮后,提交到b.jsp页面,此页面的编码
<%@ page contentType="text/html;charset=gb2312"%>
request.setCharacterEncoding("gb2312");
String aaa = request.getParameter("name");
得到的是乱码“??ㄦ?峰??”,查了好多资料也没有解决?——————————————————————————
请问大家如何解决呢
a.jsp里面的编码是utf-8的,因为a.jsp的编码由于特殊需要只能是utf-8的
<%@ page contentType="text/html;charset=UTF-8"%>//是utf-8
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
在form里有一些文本框及下拉框
<form name="frmItem" action="./DoLogin.jsp" method="<%=IA_TJFS%>">
....
</form>当在a.jsp页面的文本框里输入汉字后,点提交按钮后,提交到b.jsp页面,此页面的编码
<%@ page contentType="text/html;charset=gb2312"%>
request.setCharacterEncoding("gb2312");
String aaa = request.getParameter("name");
得到的是乱码“??ㄦ?峰??”,查了好多资料也没有解决?——————————————————————————
请问大家如何解决呢
out.println(new String(request.getParameter("aaa").getBytes("UTF-8"),"GBK"));
request.setCharacterEncoding("UTF-8");
然后设置在相关处理前加上:
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");当然,我更建议你配个Filter
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class CharSetFilter implements Filter{
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
chain.doFilter(req, res);
}
public void init (FilterConfig config) throws ServletException
{}
public void destroy (){}
}
request.setCharacterEncoding("UTF-8");
这样也不行,还是出“??ㄦ?峰?? ”这样的乱码
设了,依然是乱码"��ㄦ�峰��"
还是不行呀?
或者说,一个JAVA程序有选择的选择使用那个过滤器,有没有办法??
上面这句话只对post请求有效,get请求可以在conf/web.xml下设置,
也可以new String(request.getParameter("name").getBytes("UTF-8"),"GBK"));
http://community.csdn.net/Expert/TopicView3.asp?id=4955361
String aaa =new String( request.getParameter("name").getBytes("ISO8859-1"));
但是上述大家说的方法我都试了,不行呀
1、因为我的第一个页面编码都是utf-8
2、而第二个页面的编码用什么都是乱码
3、我的server.xml 的编码是URIEncoding="GBK"
还是不行呀
byte b[]=xm.getBytes("ISO-8859-1");
xm=new String(b);
byte temp[] =str1.getBytes("ISO-8859-1");
aaa=new String(temp);
out.println(aaa);