我的代码是
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*,java.io.*"%>
<html>
<body>
<table border=1>
<tr><td>ID</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%! String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes("iso-8859-1");
result = new String(temp);
}
catch(UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
<% Class.forName("com.jdbc.mysql.Driver").newInstance();
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/web","root","51401991");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from user");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("userName")+"</td>");
out.println("<td>"+trans(rst.getString("regTime"))+"</td>");
out.println("<td>"+trans(rst.getString("email"))+"</td>");
out.println("</tr>");
}
//关闭连接、释放资源
rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>
总是报错:org.apache.jasper.JasperException: An exception occurred processing JSP page /mysql.jsp at line “Class.forName("com.jdbc.mysql.Driver").newInstance();”
我用java程序可以正常访问,但用jsp就出错
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,java.util.*,java.io.*"%>
<html>
<body>
<table border=1>
<tr><td>ID</td><td>书名</td><td>出版社</td><td>价格</td></tr>
<%! String trans(String chi)
{
String result = null;
byte temp [];
try
{
temp=chi.getBytes("iso-8859-1");
result = new String(temp);
}
catch(UnsupportedEncodingException e)
{
System.out.println (e.toString());
}
return result;
}
%>
<% Class.forName("com.jdbc.mysql.Driver").newInstance();
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/web","root","51401991");
Statement stmt=con.createStatement();
ResultSet rst=stmt.executeQuery("select * from user");
while(rst.next())
{
out.println("<tr>");
out.println("<td>"+rst.getString("userName")+"</td>");
out.println("<td>"+trans(rst.getString("regTime"))+"</td>");
out.println("<td>"+trans(rst.getString("email"))+"</td>");
out.println("</tr>");
}
//关闭连接、释放资源
rst.close();
stmt.close();
con.close();
%>
</table>
</body>
</html>
总是报错:org.apache.jasper.JasperException: An exception occurred processing JSP page /mysql.jsp at line “Class.forName("com.jdbc.mysql.Driver").newInstance();”
我用java程序可以正常访问,但用jsp就出错
Class.forName("com.jdbc.mysql.Driver");
Connection con=java.sql.DriverManager.getConnection("jdbc:mysql://localhost/web","root","51401991");