jsp页面显示中文
环境: tomcat5.0 + jdk1.4
利用javabean 从数据库取得记录, 然后在jsp页面显示。
如果不加 <%@ page contentType= "text/html;charset=GB2312 " %> , 取得的中文可以正常显示, 但加上以后反而显示乱码。
但在javabean中自己加入的中文, 如果不在页面中加 <%@ page contentType= "text/html;charset=GB2312 " %> 就会显示乱码。
请高手指教。
------解决方案--------------------用utf-8编码呀,rx
<%@ page contentType= "text/html; charset=utf-8 "
pageEncoding= "utf-8 "%>
------解决方案--------------------你的数据库记录转换一下
rs.getString(1).getBytes( "iso-8859-1 ").toString()
------解决方案--------------------改一下数据库的字符集
------解决方案--------------------实现方法是很多的,呵呵,你只能根据自己数据的情况选择合适的,并非所有方法都适合你的。
------解决方案--------------------rs.getString(1).getBytes( "GBK ").toString()
用这个试试,看好使吗?
------解决方案--------------------应该是数据库字符集的问题。
------解决方案--------------------用utf-8编码shishi
------解决方案--------------------数据库的字符集要与页面的
<%@ page contentType= "text/html;charset=? " %>
字符集一致
------解决方案--------------------把数据库的字符集改为utf-8
------解决方案--------------------utf-8
------解决方案--------------------1、 <%@ page contentType= "text/html;charset=GB2312 " %> 是用于指定页面的编码,但是对于请求值得中文显示是不做处理的。
2、对于将请求值转换为中文2楼的方法是可以的,但是如果请求的参数过多,使用起来代码显得臃肿。既然你用的是Tomcat,这个问题tomcat已经实现了一个转换中文的过滤器,配置起来也相当简单。
源码如下:
/*
* Copyright 2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License ");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS " BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package filters;
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;
/**
* <p> Example filter that sets the character encoding to be used in parsing the
* incoming request, either unconditionally or only if the client did not
* specify a character encoding. Configuration of this filter is based on
* the following initialization parameters: </p>
* <ul>
* <li> <strong> encoding </strong> - The character encoding to be configured
* for this request, either conditionally or unconditionally based on
* the <code> ignore </code> initialization parameter. Th