JSP中文显示乱码及数据中也显示乱码的问题,高手进啊!!!

来源:百度知道 编辑:UC知道 时间:2024/06/04 08:54:24
后台添加新闻后,数据库中和前台均显示为乱码,不知道怎么个情况

index.jsp为:
<%@ page contentType="text/html; charset=GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>新闻中心</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page&quo

在两个页面前面都加上
<%request.setCharacterEncoding("gb2312")%>
强制类型转换

同时还应该注意数据库的编码集设置,你用的是mysql吗,它的默认编码集是utf-8,ms sql server这种问题不常见。