我在所有页面都添加了如下代码:
<%@ page language="java" contentType="text/html;charset=gb2312" pageEncoding="GBK"%>
response.setContentType("text/html;charset=GBK");
我的页面的表单提交都是post方法,我在:
web.xml的配置:
<?xml version="1.0" encoding="GB2312"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>encoding</filter-name>
<filter-class>com.htt.Encoding</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Encoding.java的代码:
package com.htt;
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;
public class Encoding implements Filter {
public void destroy() { }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK");
chain.doFilter(request, response); }
public void init(FilterConfig filterConfig) throws ServletException { }
} 在数据库中的中文字符都能正常显示,为什么jsp页面都是不能显示中文了???
请高手们帮助,不要提供链接,网上处理办法我都看了两天了,都没有结果!!
等待高手!!
<%@ page language="java" contentType="text/html;charset=gb2312" pageEncoding="GBK"%>
response.setContentType("text/html;charset=GBK");
我的页面的表单提交都是post方法,我在:
web.xml的配置:
<?xml version="1.0" encoding="GB2312"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>encoding</filter-name>
<filter-class>com.htt.Encoding</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Encoding.java的代码:
package com.htt;
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;
public class Encoding implements Filter {
public void destroy() { }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK");
chain.doFilter(request, response); }
public void init(FilterConfig filterConfig) throws ServletException { }
} 在数据库中的中文字符都能正常显示,为什么jsp页面都是不能显示中文了???
请高手们帮助,不要提供链接,网上处理办法我都看了两天了,都没有结果!!
等待高手!!
<%@ page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
raoyongchao
你好,具体如何编写UTF-8???
能说得详细点吗?代码怎么改???
数据库用的是oracle,
数据库的编码是什么东西,怎么写啊?
<%@ page contentType="text/html" pageEncoding="GBK"%>
jsp中再加上request.setCharacterEncoding("GBK")进行乱码处理
问题1:
我原来的代码中都有:
response.setContentType("text/html;charset=GBK");
为什么要改成:
request.setCharacterEncoding("GBK")问题2:
<%@ page language="java" contentType="text/html;charset=GBK" pageEncoding="GBK"%>
为什么要改成:
<%@ page contentType="text/html" pageEncoding="GBK"%>
?
试下
没用啊!
我所有的东西都改成了“UTF-8”了。
1 连wen-inf文件夹下的web.xml中的都改成“UTF-8”,
2 tomcat下的server.xml文件中的也改成“UTF-8”了。
3 每个jsp页面都有:
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
request.setCharacterEncoding("UTF-8");
4 还写了一个过滤器,也是“UTF-8”。现在应该一致了吧!!
可是还是把中文显示为乱码了????
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
<meta http-equiv="Content-Type" contect="text/html";charset=gb_2312-80">
看这个
http://blog.csdn.net/feg545/archive/2011/02/22/6200710.aspxWEB.XML属于XML文件,建议编码格式为UTF-8ORACLE国际版的默认编码类似于GBK,但UTF-8也不会有乱码,兼容性还是很好的。有时MYECLIPSE会犯病,你可以到Tomcat/work/cataLina/项目/JSP文件名_jsp.java
用记事本打开,会看到里面有很多乱码,把乱码全部删除掉,再用MyEclipse重新添加中文就没有问题了。
<meta http-equiv="Content-Type" contect="text/html";charset=UTF-8">
http://blog.csdn.net/wgw335363240/archive/2010/12/06/6059489.aspx
改了改,依旧老毛病。
我现在所有的地方都换成了“UTF-8”,就差数据库没改了。
之后几天,我又运行试试结果又是乱码,第二天试又正常 = =
我都彻底无语了…