再开一贴:乱码问题

bhwhy 2007-04-29 12:56:09
上一问题:
http://community.csdn.net/Expert/topic/5501/5501106.xml?temp=1.087588E-02

我把所有的jap文件的开头增加了
<%@ page contentType="text/html;charset= UTF-8" %>
增加了一个过滤器:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

public class EncodingFilter implements Filter{
private String encoding="UTF-8";
public void init(FilterConfig config)throws ServletException
{
String s = config.getInitParameter("Encoding");
if(s!=null)
{
this.encoding=s;
}
}//init

public void doFilter(ServletRequest req,ServletResponse resp,FilterChain chain)throws ServletException,IOException
{
req.setCharacterEncoding(encoding);
resp.setCharacterEncoding(encoding);
chain.doFilter(req,resp);
}
public void destroy()
{
this.encoding = "UTF-8";
}

}
在web.xml中作了配置:
<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>addressbook.filter.EncodingFilter</filter-class>
<init-param>
<param-name>Encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
我用的是struts,IDE为eclipse,数据库为mysql,eclipse中我把编码改为UTF-8,mysql我直接修改的my.ini文件,默认的是latin1,改为UTF-8.
现在问题是index.jsp没有问题了。我一转到logon.jsp报错,logon.jsp中包含的其他的jsp页面我统统都加了<%@ page contentType="text/html;charset= UTF-8" %>,logon.jsp对应有一个form,还有一个action,现在是打不开logon.jsp,我在index.jsp中用的link转的。

[jsp] - servlet jsp 的Servlet.service()出现错误<org.apache.jasper.JasperException: 没有支持的编码: UTF-8
请问是什莫地方我忽落了吗。
解决后一起结帖
...全文
255 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
bhwhy 2007-04-29
  • 打赏
  • 举报
回复
搞定了。我用包含jsp页面,每个页面都加了<%@ page contentType="text/html; charset=UTF-8"%>
搞的重复定义了。多谢大家关注。结贴
fengfangfang 2007-04-29
  • 打赏
  • 举报
回复
都使用gbk呢

wuhuawu09 2007-04-29
  • 打赏
  • 举报
回复
gbk 或gb2312试试
jk88811 2007-04-29
  • 打赏
  • 举报
回复
支持一下, 统一使用UTF-8编码确实是不错的选择...
bhwhy 2007-04-29
  • 打赏
  • 举报
回复
我的页面中没有servlet.jsp这个jsp叶面
bhwhy 2007-04-29
  • 打赏
  • 举报
回复
还是不行。我的logon.jsp主体部分代码
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="taglibs.jsp" %>
<html:errors/>
<%= application.getAttribute("userName")%>
<%= application.getAttribute("password")%>
<html:form action="/logon.do" focus="userName" >
<center>
<table border="0" width="100%">

<tr>
<th align="right">
<bean:message key="prompt.username"/>
</th>
<td align="left">
<html:text property="userName" size="15" maxlength="15"/>
</td>
</tr>

<tr>
<th align="right">
<bean:message key="prompt.password"/>
</th>
<td align="left">
<html:password property="password" size="15" maxlength="15"
redisplay="false"/>
</td>
</tr>

<tr>
<td align="right">
<html:submit property="submit" >
<bean:message key="button.logon"/>
</html:submit>

</td>
<td align="left">
<html:reset >
<bean:message key="button.reset"/>
</html:reset>

</td>
</tr>

</table>
</center>
</html:form>



dreamover 2007-04-29
  • 打赏
  • 举报
回复
去掉这句
resp.setCharacterEncoding(encoding);
junyingguang 2007-04-29
  • 打赏
  • 举报
回复
有可能是你的service 方法中有问题,或是你看看servlet.jsp是不是哪个地方传得不对
或是eclipse 软件出现了问题,都有可能!
For_suzhen 2007-04-29
  • 打赏
  • 举报
回复
关注
bingobird 2007-04-29
  • 打赏
  • 举报
回复
把下面这段去掉试试:
<filter-mapping>
<filter-name>EncodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
chengchaog 2007-04-29
  • 打赏
  • 举报
回复

81,092

社区成员

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

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