JSPTag中的中文问题?(高难问题)

wuyg719 2003-11-21 11:11:34
JSPTag中的中文问题?(高难问题)

我在doAfterBody()中写了如下一段代码

JspWriter out=bodyContent.getEnclosingWriter();
Msg="name=张三";
out.println(Msg);

然后我在JSP中写上 charset=UTF-8"
JSP页面能正常显示汉字
但由于JSP页面大部分要由页面美工处理,他们的工具不识别 UTF-8
因此他们加在JSP页面上的汉字是GB2312,运行时是乱码

我改成
JspWriter out=bodyContent.getEnclosingWriter();
Msg="name=张三";
Msg=new String(Msg.getBytes("UTF-8"),"GB2312");
out.println(Msg);
然后在JSP中写上 charset=GB2312"

结果发现运行时还是乱码。

各位高手有什么解决办法?
...全文
63 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyg719 2003-12-09
  • 打赏
  • 举报
回复
程序为什么不能解决?
Leemaasn 2003-12-01
  • 打赏
  • 举报
回复
用 FrontPage 2002打开,然后选择网页属性,改好码存一下,一般就转好了。
FRONTPAGE里面是不会出现乱码的,输出要试几次,你就明白了。主义,JSP里定义的输出码和
HTML里的输出码要保持一致。
比如
HTML里定义的:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
JSP里必须写成:
<%@ page contentType="text/html;charset=utf-8" %>
yjawal8071 2003-12-01
  • 打赏
  • 举报
回复
给你段代码看看
在jsp页面中用useBean实现
package com.yangjun.struts.code;

public class CharCode
{
public static String UnicodeToChinese(String s)
{
try
{
if(s==null || s.equals(""))
return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
return newstring;
}
catch(Exception e)
{
return s;
}
}
public static String ChineseToUnicode(String s)
{
try
{
if(s==null || s.equals(""))
return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312"),"ISO8859_1");
return newstring;
}
catch(Exception e)
{
return s;
}
}
}
wuyg719 2003-12-01
  • 打赏
  • 举报
回复
up
wuyg719 2003-11-26
  • 打赏
  • 举报
回复
up
cyougyoku 2003-11-21
  • 打赏
  • 举报
回复
用 FrontPage 2002打开,然后选择网页属性,改好码存一下,一般就转好了。
FRONTPAGE里面是不会出现乱码的,输出要试几次,你就明白了。主义,JSP里定义的输出码和
HTML里的输出码要保持一致。
比如
HTML里定义的:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
JSP里必须写成:
<%@ page contentType="text/html;charset=utf-8" %>

81,094

社区成员

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

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