编码问题老生常问

coolroy2000 2007-01-22 10:40:53
eclipse3.1+myeclipse4.1+tomcat5

在web.xml中加入
<filter>
<filter-name>SetCharacterEncoding</filter-name>
<filter-class>com.talkweb.tb.filter.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>GBK</param-value>
</init-param>
<init-param>
<param-name>enable</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetCharacterEncoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

对应的filter代码为

public class SetCharacterEncodingFilter implements Filter {

protected FilterConfig filterConfig;

protected String encodingName;

protected boolean enable;

public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
loadConfigParams();
}

private void loadConfigParams() {
// encoding
this.encodingName = this.filterConfig.getInitParameter("encoding");
// filter enable flag...
String strIgnoreFlag = this.filterConfig.getInitParameter("enable");
if (strIgnoreFlag.equalsIgnoreCase("true")) {
this.enable = true;
} else {
this.enable = false;
}
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (this.enable) {
request.setCharacterEncoding(this.encodingName);
}
chain.doFilter(request, response);
}

public void destroy() {
}

}

页面如下

<%@ page contentType="text/html; charset=GBK" %>
<%%>
<%=request.getParameter("keyword")%>
<html>
<head>
<title></title>
</head>
<body>
<form>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<tr>
<td height="20" width="35%">  查询:
<input type="text" name="keyword" value="" size="20"> 
<input type="submit" value="11" size="20">
</td>

</table>

</form>
</body>
</html>

输入后在页面显示乱码!!!

该如何解决????
...全文
244 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jacky_Dai_ 2007-01-24
  • 打赏
  • 举报
回复
来晚了啊,问题都解决了,呵呵
coolroy2000 2007-01-24
  • 打赏
  • 举报
回复
楼上的说weblogic 在服务端编码默认是 UTF-8吗?

那要怎么改呢?呵呵
wenchaohu213 2007-01-24
  • 打赏
  • 举报
回复
反正weblogic是可能出现这个问题的,

使用变码方式不对就是乱麻,GBK与UTF-8的不同
coolroy2000 2007-01-24
  • 打赏
  • 举报
回复
问题已经解决,要分的进来。
原来是tomcat端要进行设置useBodyEncodingForURI="true"
但还是有个疑问,不知道webshpere会不会有问题,请教经历过的朋友。
dovelee 2007-01-22
  • 打赏
  • 举报
回复
帮顶
coolroy2000 2007-01-22
  • 打赏
  • 举报
回复
急问。
coolzeze 2007-01-22
  • 打赏
  • 举报
回复
到我的blog上找

http://blog.csdn.net/coolzeze

58,454

社区成员

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

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