- 浏览: 1525213 次
- 性别:
- 来自: 杭州
文章分类
- 全部博客 (525)
- SEO (16)
- JAVA-EE-Hibernate (6)
- JAVA-EE-Struts (29)
- JAVA-EE-Spring (15)
- Linux (37)
- JAVA-SE (29)
- NetWork (1)
- CMS (14)
- Semantic Research (3)
- RIA-Flex (0)
- Ajax-Extjs (4)
- Ajax-Jquery (1)
- www.godaddy.com (0)
- SSH (34)
- JavaScript (6)
- SoftwareEngineer (9)
- CMMI (0)
- IDE-Myeclipse (3)
- PHP (1)
- Algorithm (3)
- C/C++ (18)
- Concept&Items (2)
- Useful WebSite (1)
- ApacheServer (2)
- CodeReading (1)
- Socket (2)
- UML (10)
- PowerDesigner (1)
- Repository (19)
- MySQL (3)
- SqlServer (0)
- Society (1)
- Tomcat (7)
- WebService (5)
- JBoss (1)
- FCKeditor (1)
- PS/DW/CD/FW (0)
- DesignPattern (11)
- WebSite_Security (1)
- WordPress (5)
- WebConstruction (3)
- XML|XSD (7)
- Android (0)
- Project-In-Action (9)
- DatabaseDesign (3)
- taglib (7)
- DIV+CSS (10)
- Silverlight (52)
- JSON (7)
- VC++ (8)
- C# (8)
- LINQ (1)
- WCF&SOA (5)
- .NET (20)
- SOA (1)
- Mashup (2)
- RegEx (6)
- Psychology (5)
- Stock (1)
- Google (2)
- Interview (4)
- HTML5 (1)
- Marketing (4)
- Vaadin (2)
- Agile (2)
- Apache-common (6)
- ANTLR (0)
- REST (1)
- HtmlAnalysis (18)
- csv-export (3)
- Nucth (3)
- Xpath (1)
- Velocity (6)
- ASP.NET (9)
- Product (2)
- CSS (1)
最新评论
-
lt26w:
理解成门面模式应该比较容易明白吧
FacadePattern-Java代码实例讲解 -
lt26w:
看下面的例子比较明白.
FacadePattern-Java代码实例讲解 -
javaloverkehui:
这也叫文档,别逗我行吗,也就自己看看。
HtmlCleaner API -
SE_XiaoFeng:
至少也应该写个注释吧。
HtmlCleaner API -
jfzshandong:
...
org.springframework.web.filter.CharacterEncodingFilter 配置
1、修改MySql数据库的my.ini配置文件、
# CLIENT SECTION
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
# ----------------------------------------------------------------------
#
# The following options will be read by MySQL client applications.
# Note that only client applications shipped by MySQL are guaranteed
# to read this section. If you want your own MySQL client program to
# honor these values, you need to specify it as an option during the
# MySQL client library initialization.
#
[client]
port=3306
default-character-set=GBK
#此处默认编码修改为GBK或utf-8
# SERVER SECTION
# ----------------------------------------------------------------------
#
2、创建数据表的时候
# 主机: localhost
# 数据库: cits
# 表: 'article'
#
CREATE TABLE `article` (
`article_id` varchar(100) NOT NULL default '0',
`article_title` varchar(100) default NULL,
`domain_id` varchar(100) default NULL,
`article_text` varchar(100) default '',
`good_flg` tinyint(1) default NULL,
`lock_flg` tinyint(1) default NULL,
`top_flg` tinyint(1) default NULL,
`read_times` int(11) default NULL,
`reply_times` int(11) default NULL,
`last_reply` char(6) default NULL,
`last_reply_time` datetime default NULL,
`add_user` varchar(30) default NULL,
`add_date` datetime default NULL,
`upd_user` varchar(30) default NULL,
`upd_date` datetime default NULL,
PRIMARY KEY (`article_id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
# 数据库: cits
# 表: 'article'
#
CREATE TABLE `article` (
`article_id` varchar(100) NOT NULL default '0',
`article_title` varchar(100) default NULL,
`domain_id` varchar(100) default NULL,
`article_text` varchar(100) default '',
`good_flg` tinyint(1) default NULL,
`lock_flg` tinyint(1) default NULL,
`top_flg` tinyint(1) default NULL,
`read_times` int(11) default NULL,
`reply_times` int(11) default NULL,
`last_reply` char(6) default NULL,
`last_reply_time` datetime default NULL,
`add_user` varchar(30) default NULL,
`add_date` datetime default NULL,
`upd_user` varchar(30) default NULL,
`upd_date` datetime default NULL,
PRIMARY KEY (`article_id`)
) ENGINE=MyISAM DEFAULT CHARSET=gbk;
此处要用GBK编码
3、在jsp页面中使用UTF-8编码
<%
Object init = request.getAttribute("init");
String domainId = (String)request.getAttribute("domainId");
if ((init == null) || (init.equals("")) || (init.equals("null"))) {
response.sendRedirect("./listArticle.do?domainId="+domainId);
} else {
%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import ="java.util.HashMap"%>
<%@ page import ="java.util.List"%>
<%@ page import ="bo.*" %>
<%
List articleList = (List)request.getAttribute("articleList");
//String domainId = (String)request.getAttribute("domainId");
int size = 0;
if(articleList !=null){
size = articleList.size();
}
%>
Object init = request.getAttribute("init");
String domainId = (String)request.getAttribute("domainId");
if ((init == null) || (init.equals("")) || (init.equals("null"))) {
response.sendRedirect("./listArticle.do?domainId="+domainId);
} else {
%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import ="java.util.HashMap"%>
<%@ page import ="java.util.List"%>
<%@ page import ="bo.*" %>
<%
List articleList = (List)request.getAttribute("articleList");
//String domainId = (String)request.getAttribute("domainId");
int size = 0;
if(articleList !=null){
size = articleList.size();
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>帖子列表</title>
</head>
<body>
<p align="center"><a href="articleSave.jsp?domainId=<%=domainId%>">发表新主题</a></p>
<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#6666FF">
<tr>
<td bgcolor="#6666FF"><div align="center">回/点击</div></td>
<td bgcolor="#6666FF"><div align="center">标题</div></td>
<td bgcolor="#6666FF"><div align="center">发表时间</div></td>
<td bgcolor="#6666FF"><div align="center">发帖人</div></td>
<td bgcolor="#6666FF"><div align="center">最后回复</div></td>
</tr>
<%for(int i = 0;i<size;i++){%>
<tr>
<td><div align="center"><%=((Article)articleList.get(i)).getReplyTimes()%><br>
<%=((Article)articleList.get(i)).getReadTimes()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getArticleTitle()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getAddDate()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getAddUser()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getLastReply()%></div></td>
</tr>
<%}%>
</table>
</body>
</html>
<%}%>
<html>
<head>
<title>帖子列表</title>
</head>
<body>
<p align="center"><a href="articleSave.jsp?domainId=<%=domainId%>">发表新主题</a></p>
<table width="800" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#6666FF">
<tr>
<td bgcolor="#6666FF"><div align="center">回/点击</div></td>
<td bgcolor="#6666FF"><div align="center">标题</div></td>
<td bgcolor="#6666FF"><div align="center">发表时间</div></td>
<td bgcolor="#6666FF"><div align="center">发帖人</div></td>
<td bgcolor="#6666FF"><div align="center">最后回复</div></td>
</tr>
<%for(int i = 0;i<size;i++){%>
<tr>
<td><div align="center"><%=((Article)articleList.get(i)).getReplyTimes()%><br>
<%=((Article)articleList.get(i)).getReadTimes()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getArticleTitle()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getAddDate()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getAddUser()%></div></td>
<td><div align="center"><%=((Article)articleList.get(i)).getLastReply()%></div></td>
</tr>
<%}%>
</table>
</body>
</html>
<%}%>
4、给Web应用加上过滤器,做一个Fiter,对所有请求统一使用UTF-8编码
下面是Fiter的源代码
package com.util.common;
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.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class EncodingFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void init(FilterConfig filterConfig) throws ServletException {
// TODO Auto-generated method stub
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
System.out.println("====initEncodingFilter");
String value = filterConfig.getInitParameter("ignore");
if(value == null){
this.ignore = true;
}
else if(value.equalsIgnoreCase("true")){
this.ignore = true;
}
else if(value.equalsIgnoreCase("yes")){
this.ignore = true;
}
else{
this.ignore = false;
}
}
// TODO Auto-generated method stub
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
System.out.println("====initEncodingFilter");
String value = filterConfig.getInitParameter("ignore");
if(value == null){
this.ignore = true;
}
else if(value.equalsIgnoreCase("true")){
this.ignore = true;
}
else if(value.equalsIgnoreCase("yes")){
this.ignore = true;
}
else{
this.ignore = false;
}
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
if(ignore||(request.getCharacterEncoding() == null)){
String encoding = selectEncoding(request);
if(encoding!=null){
request.setCharacterEncoding(encoding);
}
}
chain.doFilter(request,response);
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
if(ignore||(request.getCharacterEncoding() == null)){
String encoding = selectEncoding(request);
if(encoding!=null){
request.setCharacterEncoding(encoding);
}
}
chain.doFilter(request,response);
}
public void destroy() {
// TODO Auto-generated method stub
this.encoding = null;
this.filterConfig = null;
// TODO Auto-generated method stub
this.encoding = null;
this.filterConfig = null;
}
protected String selectEncoding(ServletRequest request){
return(this.encoding);
}
protected String selectEncoding(ServletRequest request){
return(this.encoding);
}
}
5、在Web.xml中配置过滤器,使之能起过滤作用
在web.xml中加入下面代码
<filter>
<filter-name>Encoding</filter-name>
<filter-class>com.util.common.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-name>Encoding</filter-name>
<filter-class>com.util.common.EncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>Encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
6、在hibernate.cfg.xml里连接数据的属性项修改成如下代码
<property name="connection.url">
jdbc:mysql://localhost:3306/cits?useUnicode=true&characterEncoding=UTF-8
</property>
jdbc:mysql://localhost:3306/cits?useUnicode=true&characterEncoding=UTF-8
</property>
本操作步骤在struts1.2 + hibernate 3.1 +mysql 5.0
Windows2000平台上通过,可解决乱码问题,其他的数据库请读者自行测试
发表评论
-
java.lang.ClassCastException: java.lang.Integer
2010-01-09 12:55 1388java.lang.ClassCastException: j ... -
Error:org.springframework.web.context.ContextLoaderListener
2010-01-06 21:17 8689Error con ... -
Error configuring application listener of class org.springframework.web.context.
2010-01-06 21:11 20121急!!tomcat启动报错:Error configuring ... -
Cannot find bean org.apache.struts.taglib.html.BEAN
2009-12-29 14:29 1305Cannot find bean org.apache.str ... -
attempt to create delete event with null entity
2009-12-29 11:07 4688attempt to create delete event ... -
懒加载异常org.hibernate.LazyInitializationException: could not initialize proxy - no
2009-12-28 20:44 20209错误页面提示 could n ... -
getHibernateTemplate.load() 和get()之间的区别
2009-12-28 20:16 18751. getHibernateTemplate.load() ... -
getSession()与getHibernateTemplate()区别
2009-12-28 20:13 2567getSession()与getHibernateTempla ... -
使用Hibernate持久层 --- 2 出现的问题与解决方法总结
2009-12-28 15:04 1209使用Hibernate持久层 --- 2 出现的问题与解决方法 ... -
java.lang.NullPointerException DAO
2009-12-28 15:02 1858~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ... -
JSTL1.1中要用的jar--standard.jar jstl.jar
2009-12-09 00:35 4078gg -
Jsessionid
2009-12-07 16:22 1289(1) 这是一个 ... -
spring有三种启动方式,
2009-12-07 15:21 2473spring有三种启动方式,使用 ... -
ContextLoaderListener VS. ContextLoaderServlet
2009-12-07 15:20 3557一旦ContextLoaderServlet或Cont ... -
ERRORcheck whether you have multiple ContextLoader* definitions in your web.xml!
2009-12-07 15:17 6274ERROR:check whether you have mu ... -
从tomcat 迁移到 WebSphere 经验总结(修改)
2009-12-07 15:08 2456从tomcat 迁移到 WebSphere ... -
CGlib & asm
2009-12-07 15:01 2722缺少包出现的错误信息:cglib-2.1.3.jar CGL ... -
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTup
2009-12-07 14:57 5443Unable to instantiate default t ... -
asm.jar的冲突问题
2009-12-07 14:53 1494No configuration found. Confi ... -
异常:ERROR [org.hibernate.proxy.BasicLazyInitializer] - CGLIB Enhancement failed..
2009-12-07 14:25 1815用MyEclipse6.0写了一个spri ...
相关推荐
在本篇文章中,我们将深入探讨如何解决Struts + Hibernate + MyEclipse + Tomcat + MySQL环境中出现的乱码问题。该问题通常出现在处理中文字符时,由于编码设置不当导致中文显示为乱码或无法正常读取。为了确保系统...
总之,要解决Struts+Hibernate+MyEclipse+Tomcat+MySQL环境中的乱码问题,你需要检查并设置以上提到的所有环节的编码,确保它们统一为UTF-8。通过这种方法,可以有效地避免乱码的出现,从而提供良好的用户体验。在...
JavaWeb学生在线选课系统,使用了三大框架SSH Struts+Hibernate+Spring 编码格式是UTF-8,打开请注意调一下格式,如果出现乱码,请下载一个高级记事本例如Notepad+++直接打开 .java源文件 复制粘贴即可.内含数据库脚本...
5. **设置字符集(Set Character Set)**: 设置项目的字符集为 UTF-8,以避免中文乱码的问题。 6. **添加 Struts 功能(Add Struts Capability)**: Struts 是一种流行的 MVC 框架,通过添加 Struts 功能,可以在 ...
ed2k://|file|%E7%B2%BE%E9%80%9AJava.EE%E9%A1%B9%E7%9B%AE%E6%A1%88%E4%BE%8B-%E5%9F%BA%E4%BA%8EEclipse.Spring.Struts.Hibernate%E5%85%89%E7%9B%98%E6%BA%90%E7%A0%81.rar|70436209|475e7c3548acf955e89e378...
综上所述,解决hibernate+mysql环境下中文存入数据库乱码的问题,需要从Web应用配置、数据库配置、框架配置以及文件编码等多个方面综合考虑,确保整个数据处理链路的字符集一致且支持UTF-8。只有这样,才能确保中文...
总的来说,"Struts2+Spring2+Hibernate3整合的例子"是一个完整的Java Web开发示例,它展示了如何有效地组合这三个框架,实现MVC模式,解决中文乱码问题,并且通过Spring的管理,增强了代码的可维护性和可测试性。...
总结来说,SSH框架的集成涉及到数据库连接、Hibernate配置、Spring容器设置、Struts2拦截器配置以及处理乱码和连接池问题。通过这些步骤,开发者可以构建一个完整的Java Web应用程序,实现MVC架构,有效地管理数据...
在进行MySQL、JSP以及SSH(Struts、Spring、Hibernate)框架集成的网站开发时,中文乱码问题是一个常见的困扰。这通常是由于编码格式不一致、设置不当或处理方式错误导致的。以下是一些关键的知识点,可以帮助你解决...
在MySQL、JSP和SSH框架集成的网站开发过程中,中文乱码问题是一个常见的困扰。...这个方案在MySQL5.1和MyEclipse8.5环境下已经成功解决乱码问题,对于其他版本的环境,可能需要根据实际情况微调配置。
学生管理系统(Struts Hibernate mysql)无乱码问题。内附数据库文件,直接导入即可用。lib分成两个包lib1,lib2单独下载.把两个包一起搞到lib下即可。 这个是lib1包。你还要下载 学生管理系统(Struts Hibernate ...
学生管理系统(Struts Hibernate mysql)无乱码问题。内附数据库文件,直接导入即可用。lib分成两个包lib1,lib2单独下载.把两个包一起搞到lib下即可。 这个是lib2包。你还要下载 学生管理系统(Struts Hibernate ...
本篇文章将深入探讨涉及MySQL、jsp、Struts和Hibernate的编码问题,以及Java的IO、HTTP、Struts框架、MySQL数据库在解码过程中的处理。 首先,Java的IO包提供了对输入输出的基本支持,包括java.io和java.nio。java....
这里我们将深入探讨如何解决这个问题,主要涉及SSH(Spring、Struts、Hibernate)框架下的设置以及MySQL数据库的相关配置。 首先,我们需要了解Java中的字符编码。Java默认使用UTF-8编码,而MySQL数据库在创建时也...
在Java Web开发中,我们经常会遇到各种乱码问题,特别是在使用Hibernate、Struts和Spring等框架时。这些框架处理数据的方式以及与数据库交互的过程都可能导致字符编码不一致,从而引发乱码现象。以下是对这些技术全...
ed2k://|file|%E7%B2%BE%E9%80%9AJava.EE%E9%A1%B9%E7%9B%AE%E6%A1%88%E4%BE%8B-%E5%9F%BA%E4%BA%8EEclipse.Spring.Struts.Hibernate%E5%85%89%E7%9B%98%E6%BA%90%E7%A0%81.rar|70436209|475e7c3548acf955e89e378...
学生管理系统(Struts Hibernate mysql)无乱码问题。内附数据库文件,直接导入即可用。lib分成两个包lib1,lib2单独下载.把两个包一起搞到lib下即可。我看到很多朋友只下载lib包,这个才是源码包。
在开发环境的部署中,选择了Ubuntu操作系统,并使用BootStrap前端框架来搭建用户界面,数据库选择MySQL 5.5,服务器则使用Tomcat,开发工具选择Myeclipse 10,并已经配置好Struts2和Hibernate环境。特别需要注意的是...
对于基于SSH(Spring+Struts2+Hibernate)框架的Web应用来说,解决中文乱码通常需要从多个层面入手。 ##### 2.1 配置Struts2的国际化编码 可以在`struts.xml`文件中添加如下配置来设置应用默认使用的编码格式: `...
7. **Struts与Hibernate集成**:在描述中提到了struts+hibernate+mysql的中文乱码问题,这涉及到数据库连接、字符编码设置以及两者框架的整合。Hibernate是一个对象关系映射(ORM)工具,可以将Java对象与数据库表...