为什么我的JSP程序想数据库存入汉字时会出现乱码?怎么解决啊?
我把存入数据库的源JSP代码贴上来给大家看看,请大家帮我想办法啊!!巨分奉上!<%@pagelanguage="java"import="java.util.*"page...
我把存入数据库的源JSP代码贴上来给大家看看,请大家帮我想办法啊!!巨分奉上!
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
%>
<jsp:useBean id="connDbBean" scope="page" class="db.db"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title>招标公告更新</title>
</head>
<body>
<%
String gid=request.getParameter("gid");
String biaoti=request.getParameter("biaoti");
String starttime=request.getParameter("starttime");
String endtime=request.getParameter("endtime");
String stract=request.getParameter("stract");
String shuoming=request.getParameter("shuoming");
String status="开放";
session.setAttribute("gid",gid);
String sql="insert into zhaobiao(gid,biaoti,stract,status,shuoming,starttime,endtime) values('"+gid+"','"+biaoti+"','"+stract+"','"+status+"','"+shuoming+"','"+starttime+"','"+endtime+"')";
connDbBean.executeUpdate(sql);
out.print("<script>alert('添加成功!');location.href='chanpin_add.jsp';</script>");
%>
</body>
</html>
汉字存入数据库后在数据库中显示为一连串的问号乱码。。。 展开
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
%>
<jsp:useBean id="connDbBean" scope="page" class="db.db"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
<title>招标公告更新</title>
</head>
<body>
<%
String gid=request.getParameter("gid");
String biaoti=request.getParameter("biaoti");
String starttime=request.getParameter("starttime");
String endtime=request.getParameter("endtime");
String stract=request.getParameter("stract");
String shuoming=request.getParameter("shuoming");
String status="开放";
session.setAttribute("gid",gid);
String sql="insert into zhaobiao(gid,biaoti,stract,status,shuoming,starttime,endtime) values('"+gid+"','"+biaoti+"','"+stract+"','"+status+"','"+shuoming+"','"+starttime+"','"+endtime+"')";
connDbBean.executeUpdate(sql);
out.print("<script>alert('添加成功!');location.href='chanpin_add.jsp';</script>");
%>
</body>
</html>
汉字存入数据库后在数据库中显示为一连串的问号乱码。。。 展开
展开全部
第一 如果你是用的是tomcat 容器 这个要设置一下 URIEncoding = “GBK”
下面这两行代码 编码最好一致。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
你也可以是用 String str = new String(构造字符编码)
下面这两行代码 编码最好一致。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 ">
你也可以是用 String str = new String(构造字符编码)
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询