| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1045 人关注过本帖
标题:今天刚研究JSP乱码问题,按照大家总结的经验一步步的做,但是始终解决不了。 ...
取消只看楼主 加入收藏
Grace_TT
Rank: 1
等 级:新手上路
威 望:1
帖 子:324
专家分:0
注 册:2005-12-21
收藏
 问题点数:0 回复次数:2 
今天刚研究JSP乱码问题,按照大家总结的经验一步步的做,但是始终解决不了。
我是在MyEclipse+Eclipse+tomcat5.0 中写的程序,
在一个.jsp中添加了:<%@ page contentType="text/html; charset=GBK" pageEncoding="GBK"%>
和:<%request.setCharacterEncoding("GB2312");%>
然后我保存文件,在保存的过程中,MyEclipse就会询问我:The encoding (ISO-8859-1)cannot convert some characters(such as the one in position 567).Press 'OK' to save anyway(and some characters will be convert '?' in the saved file),or press 'cansel' to return to the editor.

我只能点击OK。然后部署它,可是这个.jsp文件在Tomcat下里面的中文全都是乱码了,我用IE执行它,永远都显示的是乱码。

这要怎么做呢,难道你们都不用MyEclipse+Eclipse+tomcat5.0来编写.jsp吗?
搜索更多相关主题的帖子: JSP 乱码 经验 研究 
2006-06-29 18:12
Grace_TT
Rank: 1
等 级:新手上路
威 望:1
帖 子:324
专家分:0
注 册:2005-12-21
收藏
得分:0 
谢谢你呀,
不过要一个一个的实现呀,那不累死了!
2006-06-30 09:47
Grace_TT
Rank: 1
等 级:新手上路
威 望:1
帖 子:324
专家分:0
注 册:2005-12-21
收藏
得分:0 
以下是引用神vLinux飘飘在2006-7-8 22:19:27的发言:
过滤器代码
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.UnavailableException;

public class SetEncodingFilter
implements Filter {

protected String encoding = null;

protected FilterConfig filterConfig = null;

protected boolean ignore = true;

public void destroy() {
this.encoding = null;
this.filterConfig = null;
}

public void doFilter(
ServletRequest request,
ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
request.setCharacterEncoding(selectEncoding(request));
}
chain.doFilter(request, response);
}

public void init(FilterConfig filterConfig) throws ServletException {

this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true") || value.equalsIgnoreCase("yes"))
this.ignore = true;
else
this.ignore = false;
}


protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}

public FilterConfig getFilterConfig() {
return filterConfig;
}

public void setFilterConfig(FilterConfig filterConfig) {
this.filterConfig = filterConfig;
}

}



web.xml关于过滤器的配置
<filter>
<filter-name>SetEncodingFilter</filter-name>
<filter-class>enova.util.SetEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>SetEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>



dispatcher 起了什么作用?

过滤器只能解决数据库的乱码呢,还是所有的乱码都能解决?

[此贴子已经被作者于2006-7-24 20:30:59编辑过]

2006-07-24 20:29
快速回复:今天刚研究JSP乱码问题,按照大家总结的经验一步步的做,但是始终解决 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016994 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved