eclipse 中文乱码

K3v 2014-04-24 10:54:12
写了一个servlet
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String name=request.getParameter("username");
String password=request.getParameter("password");


System.out.println(name);
System.out.println(new String(name.getBytes("iso-8859-1"),"GBK"));
System.out.println("========================");
name = java.net.URLDecoder.decode(name, "GBK");
System.out.println(name);
System.out.println(password);


传递参数通过URL 拼接的方式
http://localhost:8080/web/LoginServlet?username=张三&&password=12345

用火狐浏览器,第二个输出乱码 其余全正常
用ie浏览器 ,全部是乱码

我当前java文件的默认编码是GBK
我已经尝试了所有的方法,tomcat里面改server.xml 加上URIEncoding="utf-8" 不成功
new String(name.getBytes("iso-8859-1"),"GBK") 不成功
java.net.URLDecoder.decode(name, "GBK"); 只有firefox成功

前辈些 我该如何解决

我用的是eclipse 不是myeclipse
...全文
132 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
鱼纹 2014-05-15
  • 打赏
  • 举报
回复
request.setCharacterEncoding("gbk"); response.setContentType("text/html;charset=gbk"); 加到doGet里面试试

24,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Apache
社区管理员
  • Apache
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧