JSP乱码问题... 我在MYSQL中添加记录,例如:“我是辉”——在JSP运行时就出现“我是?”在JSP中添加记录时,更是乱码,,,添加的都是乱码,,,这该怎么解决??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是MySql的编码问题 可以尝试下在链接MySql时指定编码格式为gbk或gb2312 就是gbk的啊,,,还乱码的啊... 就是在安装mysql的时候选择数据库的语言要用gb2312的。在就是可以在你的页面中尝试哈用字符转换的语句些哈的撒。 我给楼主的意见是最好把所有的编码格式该成UTF-8包括mysql安装时候也要选择UTF-8. jsp和数据库的编码方式不同就会出现乱码,lz可以在更新数据库的时候进行转码。 你在数据库中取到数据后,假设保存为str,那么你可以用Java代码转换一下。Byte bytes = str.getByte("utf-8");String result = new String(bytes,"bg2312");这样子你试一下行不行,不行的话改一下上面两句话的编码方式试一下。 5楼正解,最好同意编码,全部搞成UTF-8 class Encoding extends RequestProcessor{ public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // TODO Auto-generated method stub request.setCharacterEncoding("utf-8"); response.setCharacterEncoding("utf-8"); super.process(request, response); }} 能说说在哪里改编码方式吗?有哪些地方???我知道在D:\Program Files\MySQL\MySQL Server 5.0里面有一个my.ini的文件[client]port=3306[mysql]default-character-set=gbk里的gbk可以改为UTF-8还有哪里也要改,,高手们指点指点啊...能说说UTF-8有哪些好处,,,而不用gbk呢,,, 这个是指在jsp,selvet和bean中都要保持一致... I agree with this idea! 不是jsp的编码格式问题就是mysql的编码格式问题了。。 http://www.sqlserver.com.cn/c2l0ZS9zaG93Lmh0bWw_bXlpZD05NDY5url.htmlhttp://www.sqlserver.com.cn/c2l0ZS9zaG93Lmh0bWw_bXlpZD0xNjk2url.html 我在数据库中写入数据,我从数据库中取出来写入JSP中,在JSP显示是不乱码的啊...在JSP中写入数据库时就乱码啊...到底该怎么解释啊???能不能给我详细点的介绍介绍啊... jsp 页面用 editplus 重新打开,选择“另存为” 它有个编码格式 选择 “utf-8” 就OK,另外你的页面中的<%page contentType="text/html;charset=gbk"%> 也要改成UTF-8 jsp 页面用 editplus 重新打开,选择“另存为” 它有个编码格式 选择 “utf-8” 就OK,另外你的页面中的<%page contentType="text/html;charset=gbk"%> 也要改成UTF-8MYSQL 中的编码最好是utf-8 tomcat 目录下的web.xml 中的编码格式也最好是utf-8 你看看数据库表中可是乱码,如果是的话,就说明是数据库编码不对喽。如果数据库中是正确的,就写个过滤器,把所有jsp文件都过滤一下,写个类继承Filter,然后在web.xml中配置一下就可以了 能说说在DREAMWEAVER8.0,TOMCAT6.0,MYSQL5.0三个配合的,有哪些地方涉及到编码方式了吗???...能指点一下吗???以后可以多注意了解一点... 安装mysql的时候选择数据库的语言为GBK 我的mysql已经安装在电脑上,但要改它的编码格式该在哪里改??总不会重新安装啊??? 我的mysql已经安装在电脑上,但要改它的编码格式该在哪里改?? 总不会重新安装啊??? 过滤器的在web.xml中的典型配置和主要代码如下: web.xml:CharacterEncodingFilternet.vschool.web.CharacterEncodingFilterencodingGBKCharacterEncodingFilter/*CharacterEncodingFilter.java:public class CharacterEncodingFilter implements Filter {protected String encoding = null; public void init(FilterConfig filterConfig) throws ServletException {this.encoding = filterConfig.getInitParameter("encoding");}public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {request.setCharacterEncoding(encoding);response.setContentType("text/html;charset="+encoding);chain.doFilter(request, response);}} 不是你的机器的问题...不用重装数据库 在创建表或数据库时可以指定编码。create table test (....) DEFAULT CHARACTER SET utf8;楼主可以参考一下这篇文章:http://bbs.chinaunix.net/viewthread.php?tid=1177569 在数据库的链接的url上加上 ?characterEncoding=gbk 把数据库的编码格式、表的编码个格式和字段的编码格式都改为gbk。 如果是保存记录出现乱码的话,设置响应编码: response.setCharEncoding("GBK");如果是取得记录出现乱码的话,设置请求编码: request.setCharEncoding("GBK"); 楼主,首先自己确认一下你那一环上面出问题了,再想办法解决.不要一个一个方法的试,这样效率太低了比如存到数据库中已是乱码,还是从数据库中读出来是乱码呢.WEB开发中乱码的可能性太多了。比如数据库中个别汉字是乱码其他汉字正常的情况都会存在的。 解决乱码:方案一)在相关的jsp中这样写:msg是你要过滤的乱码字符串<% String message=request.getParameter("msg"); String msg=new String(message.getBytes("IOS-8859-1"),"gbk");%>方案二)在相关的jsp中这样写:str是你要过滤的乱码字符串<%! public String transStr(String str) { try{ return new String(str.getBytes("ISO-8859-1"),"gbk"); }catch(){return str;} }%> 引用<%=transStr(message)%>方法三)在相关的jsp的头部这样写:<%@ page ContextType="text/html;charset="gbk"%>方法四)或者将可能要出现乱码的字符串存储到session,application中来避免乱码session.setAttribuite("str","str");方法五)使用filter过滤器:filter里边:public class ModifyCode implements Filter { protected FilterConfig filterConfig; private String targetEncoding="UTF-8"; public void init(FilterConfig config)throws ServletException { this.filterConfig=config; this.targetEncoding=config.getInitParameter("code");//获取web.xml中code参数的值,即要过滤的字符串 } public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws ServletException { HttpServletRequest srequest=(HttpServletRequset)request; try { srequest.setCharacterEncoding(this.targetEncoding);//转码 chain.doFilter(request,response); }catch(Exception e) {e.printlStackTrace();} } public void destroy() { this.filterConfig=null; } }web.xml中的配置:<filter> <filter-name>modifyCode</filter-name> <filter-class>此filter的路径</filter-class> <init-param> <param-name>code</param-name> <param-value>UTF-8</param-value> </init-param></filter><filter-mapping> <filter-name>modifyCode</filter-name> <url-pattern>/*</url-pattern> //过滤以所有的文件</filter-mapping> jsp数据库访问 JB中调用自己写类的问题,急急急,弄了一天了 绝对经典的软件开发人员的视频教程网站--完全免费下载 HttpServletRequest 的实现类是哪一个。jsp和servlet是在怎么通过request和 response交互的 EL表达式的问题 界面设计?idea? 关于struts救急!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 自动提交按钮 如何配置JSP编程环境 请教,怎样实现IIS和resin 整合? 如何实现当前程序在其他机器上的备份 JAVABEAN调用问题
可以尝试下在链接MySql时指定编码格式为gbk或gb2312
String result = new String(bytes,"bg2312");这样子你试一下行不行,不行的话改一下上面两句话的编码方式试一下。
public void process(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// TODO Auto-generated method stub
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
super.process(request, response);
}
}
有哪些地方???
我知道在D:\Program Files\MySQL\MySQL Server 5.0里面有一个my.ini的文件
[client]port=3306[mysql]default-character-set=gbk里的gbk可以改为UTF-8还有哪里也要改,,
高手们指点指点啊...能说说UTF-8有哪些好处,,,而不用gbk呢,,,
这个是指在jsp,selvet和bean中都要保持一致...
I agree with this idea!
mysql的编码格式问题了。。
http://www.sqlserver.com.cn/c2l0ZS9zaG93Lmh0bWw_bXlpZD0xNjk2url.html
我在数据库中写入数据,我从数据库中取出来写入JSP中,在JSP显示是不乱码的啊...
在JSP中写入数据库时就乱码啊...
到底该怎么解释啊???
能不能给我详细点的介绍介绍啊...
如果数据库中是正确的,就写个过滤器,把所有jsp文件都过滤一下,写个类继承Filter,然后在web.xml中配置一下就可以了
能指点一下吗???以后可以多注意了解一点...
总不会重新安装啊???
总不会重新安装啊???
web.xml:
CharacterEncodingFilter
net.vschool.web.CharacterEncodingFilter
encodingGBKCharacterEncodingFilter
/*
CharacterEncodingFilter.java:public class CharacterEncodingFilter implements Filter
{protected String encoding = null; public void init(FilterConfig filterConfig) throws ServletException
{
this.encoding = filterConfig.getInitParameter("encoding");
}public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
{
request.setCharacterEncoding(encoding);
response.setContentType("text/html;charset="+encoding);
chain.doFilter(request, response);
}}
不是你的机器的问题...不用重装数据库
create table test (....) DEFAULT CHARACTER SET utf8;楼主可以参考一下这篇文章:http://bbs.chinaunix.net/viewthread.php?tid=1177569
把数据库的编码格式、表的编码个格式和字段的编码格式都改为gbk。
在相关的jsp中这样写:
msg是你要过滤的乱码字符串
<%
String message=request.getParameter("msg");
String msg=new String(message.getBytes("IOS-8859-1"),"gbk");
%>方案二)
在相关的jsp中这样写:
str是你要过滤的乱码字符串
<%! public String transStr(String str)
{
try{
return new String(str.getBytes("ISO-8859-1"),"gbk");
}catch(){return str;}
}
%> 引用<%=transStr(message)%>
方法三)
在相关的jsp的头部这样写:
<%@ page ContextType="text/html;charset="gbk"%>
方法四)
或者将可能要出现乱码的字符串存储到session,application中来避免乱码
session.setAttribuite("str","str");方法五)
使用filter过滤器:filter里边:
public class ModifyCode implements Filter
{
protected FilterConfig filterConfig;
private String targetEncoding="UTF-8";
public void init(FilterConfig config)throws ServletException
{
this.filterConfig=config;
this.targetEncoding=config.getInitParameter("code");//获取web.xml中code参数的值,即要过滤的字符串
} public void doFilter(ServletRequest request,ServletResponse response,FilterChain chain)throws ServletException
{
HttpServletRequest srequest=(HttpServletRequset)request;
try
{
srequest.setCharacterEncoding(this.targetEncoding);//转码
chain.doFilter(request,response);
}catch(Exception e)
{e.printlStackTrace();}
} public void destroy()
{
this.filterConfig=null;
}
}
web.xml中的配置:
<filter>
<filter-name>modifyCode</filter-name>
<filter-class>此filter的路径</filter-class>
<init-param>
<param-name>code</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter><filter-mapping>
<filter-name>modifyCode</filter-name>
<url-pattern>/*</url-pattern> //过滤以所有的文件
</filter-mapping>