数据在数据库中查询显示是中文,输出到页面转换为utf-8之后,输出为乱码,求解 3C

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">



Insert title here


<%
String url = "jdbc:odbc:DSSchool;useunicode=true;characterEncoding=UTF-8";
String sqlstr,no,name;
int age;
Connection con; // 建立连接类
Statement stmt; // 建立SQL语句执行类
ResultSet rs = null;// 建立结果集类
// 告诉程序使用JDBC与ODBC桥建立数据库连接
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(url,"sa","123456");
stmt = con.createStatement();
sqlstr = "select * from T_STUDENT";
rs = stmt.executeQuery(sqlstr);
while (rs.next()){
String stuno = new String (rs.getString("STUNO").getBytes("GBK"),"UTF-8");
String stuname = new String ( rs.getString("STUNAME").getBytes("GBK"),"UTF-8");
out.print(stuno+" "+stuname + " "+"
");
}
stmt.close();
con.close();
%>

1个回答

格式问题和保存在软件的下载位置

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问