jsp连接数据库问题
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* " errorPage= "exception.jsp " %>
<html>
<body>
<%/***********************************************
/*
/*DbTest.java
/*http://www.knowsky.com
/******************************************* */
public class DbTest {
Connection con;
Statement sta;
ResultSet rs;
String driver;
String url;
String user;
String pwd;
public DbTest()
{
driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";;
url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName =guolv ";
user = "sa ";
pwd = "pass ";
init();
}
public void init()
{
try{
Class.forName(driver);
System.out.println( "driver is ok ");
con = DriverManager.getConnection(url,user,pwd);
System.out.println( "conection is ok ");
sta = con.createStatement();
rs = sta.executeQuery( "select * from logonerr ");
while(rs.next())
System.out.println(rs.getInt( "id "));
}catch(Exception e)
{
e.printStackTrace();
}
}
public static void main(String args [])//自己替换[]
{
new DbTest();
}
}
%>
</body>
</html>
以上是代码
下面是错误代码
刚学习jsp 不怎么看的懂
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:156)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
org.apache.jasper.JasperException: Unable to load class for JSP
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:600)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.ClassNotFoundException: org.apache.jsp.conn_005fsql_jsp
java.net.URLClassLoader$1.run(Unknown Source)
java.security.AccessController.doPrivileged(Native Method)
java.net.URLClassLoader.findClass(Unknown Source)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:134)
org.apache.jasper.servlet.JasperLoader.loadClass(JasperLoader.java:66)
org.apache.jasper.JspCompilationContext.load(JspCompilationContext.java:598)
org.apache.jasper.servlet.JspServletWrapper.getServlet(JspServletWrapper.java:144)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:329)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
[解决办法]
应该是驱动找不到:com.microsoft.jdbc.sqlserver.SQLServerDriver
有没有将驱动放入lib文件里?
[解决办法]
Unable to load class for JSP
如果你确定你驱动没问题,那么删除掉work目录下的文件,重起服务器,再试试看
[解决办法]
不好意思,刚没看代码就回答了...
问题很明显,你在JSP里定义了public class这样是不行的,因为JSP本身是一个servlet也就是一个class,而它自己是缺省public 的,而一个class只允许有一个public class定义,所以就没办法编译JSP...你把class定义去掉试试
[解决办法]
调用的类库文件找不到,估计是驱动jar文件没有在classpath路径里面
把驱动jar文件放到lib文件夹下,并设置classpath
开始你不要搞那么复杂啊,网上的程序也不是抄来就能直接用的,要有环境设置啊
[解决办法]
建议兄弟,先好好看看书本再试,,,
我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.myexception.cn/java-web/317.html