servlet 显示中文问题

manqinglb 2007-04-20 12:29:12
大家好!
我在写了个简单的jsp页面,里面有个提交表单,提交到servlet中显示一下中文,但为什么都是乱码啊? 请给予解决,谢谢! 具体代码如下:

// jsp
<%@ page contentType="text/html; charset=GBK" %>
<%
//response.setCharacterEncoding("gb2312");
//request.setCharacterEncoding("gb2312");
%>
<html>
<head>
<title>
jsp1
</title>
</head>
<body>
<form action="./servlet1">
<table>
<tr>
<td><input type="text" name="name"><input type="submit" value="sdsdsd"></td>
</tr>
</table>
</form>
</body>
</html>
----------------------------------------------------
//servlet1的doGet方法

public void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {

// response.setCharacterEncoding("gb2312");
// request.setCharacterEncoding("gb2312");

response.setContentType("text/html; charset=GBK");
PrintWriter out = response.getWriter();
String name = new String(request.getParameter("name").getBytes("ISO-8559-1"),"gbk");
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>" + name + "</p>");
out.println("</body>");
out.println("</html>");
out.close();
}

我把在论坛里说的方法都用了,怎么还显示乱码呀! 请帮帮忙,解决后保证给分!
...全文
228 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
imA 2007-04-20
  • 打赏
  • 举报
回复
转码,可以写一个filter,关于例子可以看下面的帖子中我的回复

http://community.csdn.net/Expert/TopicView3.asp?id=5460412
imA 2007-04-20
  • 打赏
  • 举报
回复
那就结贴吧
manqinglb 2007-04-20
  • 打赏
  • 举报
回复
谢谢大家帮我解决,我也学到很多东西,所以给你们加分,以后多帮忙!~
manqinglb 2007-04-20
  • 打赏
  • 举报
回复
问题已经解决,JSP中的Method方法是POST时,在servlet中设置request.setCharacterEncoding("gb2312");
就可以了。 结贴……………………
manqinglb 2007-04-20
  • 打赏
  • 举报
回复
我加了filter 怎么还是不管用啊! 大侠 也设了映射了
jerrycccc2323 2007-04-20
  • 打赏
  • 举报
回复
转为UTF-8编码

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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