日期:2014-05-18  浏览次数:20664 次

JSP乱码问题,我刚研究过的,又出现了,这次解决不了了,大家帮忙看看怎么回事?
下面是我的JSP代码:

<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=utf-8 ">
<title> &Icirc;&THORN;±ê&Igrave;&acirc;&Icirc;&Auml;&micro;&micro; </title>
<style   type= "text/css ">
<!--
.style1   {color:   #EE0000}
-->
</style>
</head>

<body>
<h1   align= "center "> <span   class= "style1 "> 学习网站后台管理系统 </span> </h1>
<h1> &nbsp;   </h1>
</body>
</html>

只要一按“保存”就会出来对话框,下面是对话框提示:
“Save   could   not   be   completed
    Ression:
          Some   characters   cannot   be   mapped   using   "ISO-8859-1”   character   encoding   either   change   the   encoding   or   remove   the   characters   which   are   not   supported   by   the   "ISO-8859-1 "   character   encoding. "

以前我遇到这个问题时,改一下文件属性“utf-8 "就行了,可是这次还是不行,怎么回事,请多指教呀?小弟感谢不尽,急呀。。。



------解决方案--------------------
<%
request.setCharacterEncoding( "gb2312 ")
%>
------解决方案--------------------
把这一句 <meta http-equiv= "Content-Type " content= "text/html; charset=utf-8 "> 去掉
把这一句 <%@page contentType= "text/html;charset=GB2312 "%> 放在文件头
------解决方案--------------------
涉及到字符编码的都换成utf-8
文件右击的properties中字符编码的设置也是utf-8
试试!
------解决方案--------------------
1.编码问题:
(1)首先确定JSP页面头部是否有: <%@ page contentType= "text/html; charset=GBK " %>
(2)类似这样的转码:
String param= new String(request.getParameter( "param ").getBytes( "ISO-8859-1 "), "GBK ");
(3)添加filter字符过滤器,具体做法:

先添加类:

import javax.servlet.Filter;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.FilterChain;
import java.io.IOException;
import org.apache.log4j.Logger;
import java.net.URLEncoder;

/** *//**
* 请求中中文字符串过滤类
*/

public class SetEncodingFilter
implements Filter ...{
private Logger logger=Logger.getLogger(this.getClass());

public void init(FilterConfig filterConfig) throws ServletException ...{
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException ...{
logger.info( "请求转码过滤器=================== ");
request.setCharacterEncoding( "gb2312 ");
chain.doFilter(request,response);
}

public void destroy() ...{
}
}
再注册类到XML里:

<fil