JSP写入数据库中文乱码问题
小弟在学习表单,按照课本上写的在myclipse输入以下代码,当在表单项中输入中文时,数据库中总是会显示‘?’,久久无法解决,忘大神能帮小弟一把!感激!
以下是JSP代码部分:
<%@ page language="java" contentType="text/html;charset=gb2312" import="java.sql.*" %>
<%
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>My JSP 'register.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<% request.setCharacterEncoding("gb2312"); %>
添加学生信息<br>
<form method="post">
输入学号:<input type="text" name="stuno"><br>
输入姓名:<input type="text" name="stuname"><br>
输入性别:<input type="radio" name="sex" value="男" checked>男
<input type="radio" name="sex" value="女">女
<input type="submit" value="添加">
</form>
<%
String stuno=request.getParameter("stuno");
//stuno=new String(stuno.getBytes("ISO-8859-1"),"gb2312");
String stuname=request.getParameter("stuname");
//stuname=new String(stuname.getBytes("ISO-8859-1"),"gb2312");
String stusex=request.getParameter("sex");
//stusex=new String(stusex.getBytes("ISO-8859-1"),"gb2312");
&nb