第一次jsp乱码

来源:百度知道 编辑:UC知道 时间:2024/05/26 10:44:59
代码:<%@page contentType="text/html;charset=GBK"%>
<%@page pageEncoding="GB2312">
<%@page import = "java.sql.*"%>
<html>
<head><title>数据库打开与关闭!</head></title>
<body>
<%
Class.forName("sun.jdbc.odbc. JdbcOdbcDriver");
Connection con=DriveerManager.getConnection("jdbc:odbc:E:\DSN\211");
if(con.isClosed())
out.println("数据库已经关闭!<br>");
else
out.println("数据库正在打开中!<br>");
con.close();
if(con.isClosed())
out.println("数据库已经关闭!");
else
out.println("数据库正在打开中!");
%>
</body>
</html>

错误:--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error

第一行的charset就是指编码方式,结果你第二行又来了一个编码,两个不一样,电脑不知道认哪个了,不乱才怪。应该这样写一行就行了。
<%@page contentType="text/html;charset=gb2312"%> 或<%@page pageEncoding="GB2312"> 。一般都是第一行。楼上说的是UTF-8。也是中文编码的一种。。也可以采用。

<%@page pageEncoding="GB2312">
后面少了%

<%@page pageEncoding="GB2312"> 这句话你看看是不是应该把GB2312换成 转换中文的那个。。。叫什么8。。。我忘了。。呵呵你查查

页面前三行换成:<%@ page contentType="text/html;charset=gb2312" language="java" import="java.sql.*,java.util.*" errorPage="" %>