serverlet中,怎样输出汉字到httprequest(就是用户的页面)中去呀?我的怎么全是乱码呀?

smilelhh 2005-03-04 07:57:10
public void doFilter(final ServletRequest request,final ServletResponse response,FilterChain chain)throws IOException,ServletException
{
HttpServletRequest hreq = (HttpServletRequest)request;
.....
PrintWriter writer = response.getWriter();
response.setContentType("text/html; charset=GBK");
hreq.setCharacterEncoding("GBK");
writer.println("<b>页面出错啦</b>");//出来的全乱码!!!!!!!!!!!!!!!!!!!
}
...全文
161 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxmzfbdc 2005-03-09
  • 打赏
  • 举报
回复
在JSP页面中加入
<%@ page contentType="text/html;charset=GBK" language="java" %>
再serverlet中加入
response.setContentType("text/html; charset=GBK");
hreq.setCharacterEncoding("GBK");
zhl471 2005-03-08
  • 打赏
  • 举报
回复
关注
smilelhh 2005-03-07
  • 打赏
  • 举报
回复
不行呀!

我的serverlet中有这几行呀
response.setContentType("text/html; charset=GBK");
hreq.setCharacterEncoding("GBK");

smilelhh 2005-03-07
  • 打赏
  • 举报
回复
没人会呀?
浮上去
smilelhh 2005-03-05
  • 打赏
  • 举报
回复
呀?Tomcat 5有问题呀?

utf-8是吧?
suns1206 2005-03-04
  • 打赏
  • 举报
回复
忘了说,用UTF比较好,再写个过滤器类
suns1206 2005-03-04
  • 打赏
  • 举报
回复
Tomcat 5以上版本会有此问题
4.x没有
可以在JSP页面中加入
<%@ page contentType="text/html;charset=GBK" language="java" %>

62,614

社区成员

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

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