JSP页面输中文而数据库显示的是乱码,怎么回事啊? 10
代码是这样的,就是在页面熟中文,数据库里显示的是乱码,请教啊!!<%@pagecontentType="text/html;charset=gb2312"language...
代码是这样的,就是在页面熟中文,数据库里显示的是乱码,请教啊!!
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.Date" errorPage="" %>
<html>
<head>
<title>添加成功</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>
<body>
<%
String tstna=request.getParameter("shijuanming");
String tstid=request.getParameter("shijuanhao");
java.util.Date regTime=new java.util.Date();
String register_Time=regTime.toString();
String query="insert into shijuanbiao (Id,testName) values ('"+tstid+"','"+tstna+"')";
//try
//{
String sDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(sDBDriver);
String sConnStr="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=test";
String username="sa";
String pwd1="";
Connection connWeb=DriverManager.getConnection(sConnStr,username,pwd1);
Statement stmt=connWeb.createStatement();
stmt.executeUpdate(query);
stmt.close();
connWeb.close();
out.println("恭喜!您添加的信息已经写进数据库!");
//}
//catch (SQLException e)
//{
// out.println(e.getMessage());
//}
%>
</body>
</html> 展开
<%@page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.Date" errorPage="" %>
<html>
<head>
<title>添加成功</title>
<link rel=stylesheet href="style.css" type="text/css">
</head>
<body>
<%
String tstna=request.getParameter("shijuanming");
String tstid=request.getParameter("shijuanhao");
java.util.Date regTime=new java.util.Date();
String register_Time=regTime.toString();
String query="insert into shijuanbiao (Id,testName) values ('"+tstid+"','"+tstna+"')";
//try
//{
String sDBDriver="com.microsoft.jdbc.sqlserver.SQLServerDriver";
Class.forName(sDBDriver);
String sConnStr="jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=test";
String username="sa";
String pwd1="";
Connection connWeb=DriverManager.getConnection(sConnStr,username,pwd1);
Statement stmt=connWeb.createStatement();
stmt.executeUpdate(query);
stmt.close();
connWeb.close();
out.println("恭喜!您添加的信息已经写进数据库!");
//}
//catch (SQLException e)
//{
// out.println(e.getMessage());
//}
%>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询