shh+mysql乱码

xjpcj 2009-09-14 12:04:20
jsp页面设置成utf-8,mysql里面也默认为utf-8,
spring配置:jdbc:mysql://localhost:3306/shop?characterEncoding=utf-8&characterSetResults=utf-8
struts.xml配置: <constant name="struts.locale" value="zh_CN"></constant>
<constant name="struts.il8n.encoding" value="utf-8"></constant>
web.xml配置: <filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
com.shop.util.SetCharacterEncodingFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
过滤器代码:
public class SetCharacterEncodingFilter implements Filter
public void destroy() {
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)throws IOException, ServletException {

request.setCharacterEncoding("utf-8");

chain.doFilter(request, response);
}

public void init(FilterConfig filterConfig) throws ServletException {
}
}
还是乱码。
在mysql数据库中直接插入中文会出现错误:incorrect string value。
听说还要在tomcat里面插入编码,应该怎么插入编码,tomcat 的server.xml文件时这样的:<!-- Note: A "Server" is not itself a "Container", so you may not
define subcomponents such as "Valves" at this level.
Documentation at /docs/config/server.html
-->
<Server port="8005" shutdown="SHUTDOWN">

<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />
<!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html -->
<Listener className="org.apache.catalina.core.JasperListener" />
<!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html -->
<Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />

<!-- Global JNDI resources
Documentation at /docs/jndi-resources-howto.html
-->
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
-->
<Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources>

<!-- A "Service" is a collection of one or more "Connectors" that share
a single "Container" Note: A "Service" is not itself a "Container",
so you may not define subcomponents such as "Valves" at this level.
Documentation at /docs/config/service.html
-->
<Service name="Catalina">

<!--The connectors can use a shared executor, you can define one or more named thread pools-->
<!--
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
-->


<!-- A "Connector" represents an endpoint by which requests are received
and responses are returned. Documentation at :
Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
Java AJP Connector: /docs/config/ajp.html
APR (HTTP/AJP) Connector: /docs/apr.html
Define a non-SSL HTTP/1.1 Connector on port 8080
-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
This connector uses the JSSE configuration, when using APR, the
connector should be using the OpenSSL style configuration
described in the APR documentation -->
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
-->

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


<!-- An Engine represents the entry point (within Catalina) that processes
every request. The Engine implementation for Tomcat stand alone
analyzes the HTTP headers included with the request, and passes them
on to the appropriate Host (virtual host).
Documentation at /docs/config/engine.html -->

<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine name="Catalina" defaultHost="localhost">

<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->

<!-- The request dumper valve dumps useful debugging information about
the request and response data received and sent by Tomcat.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.RequestDumperValve"/>
-->

<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>

<!-- Define the default virtual host
Note: XML Schema validation will not work with Xerces 2.2.
-->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">

<!-- SingleSignOn valve, share authentication between web applications
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->

<!-- Access log processes all example.
Documentation at: /docs/config/valve.html -->
<!--
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
-->

</Host>
</Engine>
</Service>
</Server>
是哪里配置出错了,还是哪些没配置。
...全文
218 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanmingbo 2010-03-06
  • 打赏
  • 举报
回复
解决了我的问题
谢谢哈!
bea_java 2009-09-26
  • 打赏
  • 举报
回复
纯纯的接分。你都解决了,也不用多说了。
vigorlls 2009-09-26
  • 打赏
  • 举报
回复
一般解决乱码问题:统一用UTF-8(数据库,页面,项目都设置),在放个filter
andyjoo 2009-09-26
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 qq774097676 的回复:]
楼主是怎样解决的呀 我也经常出现乱码问题  添加了过滤器、jsp设置了编码、mysql也设置了编码还是没解决
[/Quote]TOMCAT server.xml里 搜索你用的端口号(比如8080)然后在 该属性后面加 URIEncoding="utf-8"
andyjoo 2009-09-26
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 andyjoo 的回复:]
TOMCAT server.xml里 搜索你用的端口号(比如8080)然后在 该属性后面加 URIEncoding="utf-8" , 还有用的工具(比如myeclipse) 也可以设置编码, 还有,建完数据库后就先把字符集编码统一了,然后建表就不用再设置了。  过滤器设置。 页面上设置。 等等。。。。 还有没有哇,请高手指点!
[/Quote]
TOMCAT server.xml里 搜索你用的端口号(比如8080)然后在 该属性后面加 URIEncoding="utf-8"
应该是这个问题
frank_fan 2009-09-25
  • 打赏
  • 举报
回复
统一用UTF-8比较好
qingkangxu 2009-09-25
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 xjpcj 的回复:]
问题已经解决了,谁过来随便说两句 分数给他
[/Quote]

楼主人真好,JF.
qq774097676 2009-09-25
  • 打赏
  • 举报
回复
楼主是怎样解决的呀 我也经常出现乱码问题 添加了过滤器、jsp设置了编码、mysql也设置了编码还是没解决
andyjoo 2009-09-25
  • 打赏
  • 举报
回复
TOMCAT server.xml里 搜索你用的端口号(比如8080)然后在 该属性后面加 URIEncoding="utf-8" , 还有用的工具(比如myeclipse) 也可以设置编码, 还有,建完数据库后就先把字符集编码统一了,然后建表就不用再设置了。 过滤器设置。 页面上设置。 等等。。。。 还有没有哇,请高手指点!
zhuzhangliang 2009-09-19
  • 打赏
  • 举报
回复
装mysql时最好设置一下编码为gb2312
dbx915 2009-09-19
  • 打赏
  • 举报
回复
修改一下 server.xml 文件,在设置端口的地方加上URIEncoding="utf-8"。

<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="utf-8"/>
liuzuowei007 2009-09-18
  • 打赏
  • 举报
回复
装mysql的时候没设置编码吧。。。
billfranck 2009-09-18
  • 打赏
  • 举报
回复
我常用的将mysql设成gb2312
coolbamboo2008 2009-09-18
  • 打赏
  • 举报
回复
mysql数据库里面,每个表,每个字段都应该设成utf-8,是不是楼主这里没有注意?帮顶帮顶~
luffyke 2009-09-18
  • 打赏
  • 举报
回复
过来顶一下
wl_ldy 2009-09-18
  • 打赏
  • 举报
回复
楼主说是问题解决了,是哪里出了问题啊,如何解决的,在编码问题方面我也是很苦恼啊!!学习!
knight14 2009-09-17
  • 打赏
  • 举报
回复
mysql my.ini 设置default-character-set=gbk
banglezwy 2009-09-17
  • 打赏
  • 举报
回复
web.xml里有配置吗
xjpcj 2009-09-17
  • 打赏
  • 举报
回复
问题已经解决了,谁过来随便说两句 分数给他
xjpcj 2009-09-14
  • 打赏
  • 举报
回复
只有一点分了,大家支持一下

50,543

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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