Chinaunix

标题: jsp链接mysql的问题 [打印本页]

作者: laohuanggua    时间: 2009-11-10 17:37
标题: jsp链接mysql的问题
我安装了mysql-5.1 server和tomcat,以及kata-connector和mysql-connector-java

已经能完好的解析这个文件

****************************************************
<%
Runtime lRuntime = Runtime.getRuntime();

out.println("***BEGIN MEMORY STATISTICS***<br />");
out.println("Free Memory:"+lRuntime.freeMemory()/1024/1024+"M<br/>");
out.println("Max Memory:"+lRuntime.maxMemory()/1024/1024+"M<br/>");
out.println("Total Memory:"+lRuntime.totalMemory()/1024/1024+"M<br/>");
out.println("Available Processors:"+lRuntime.availableProcessors()+"<br/>");
out.println("***END MEMORY STATISTICS***");
%>
****************************************************

将如下文件传送到htdocs下,却不能显示

****************************************************

<%@ page language="java" %>
<%@ page import="com.mysql.jdbc.Driver" %>
<%@ page import="java.sql.*" %>

<%

String driverName="com.mysql.jdbc.Driver";

String userName="root";

String userPasswd="";

String dbName="test";

String url="jdbc:mysql://localhost/"+dbName+"?user="+userName+"&password="+userPasswd;

Class.forName("com.mysql.jdbc.Driver").newInstance();
try
{
        Connection connection=DriverManager.getConnection(url);

        out.println(" O K !");

        connection.close();
}
catch( Exception e )
{
        out.println( "connent mysql error:" + e );
}

%>

****************************************************

报告

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 6 in the generated java file
Only a type can be imported. com.mysql.jdbc.Driver resolves to a package

Stacktrace:
        org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:92)
        org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:330)
        org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:439)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:334)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:312)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:299)
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:586)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

note The full stack trace of the root cause is available in the Apache Tomcat/6.0.20 logs.

检查日志却发现没有错误提示

tail /usr/local/apache2/logs/access_log
192.168.1.10 - - [10/Nov/2009:16:28:32 +0800] "GET /test.jsp HTTP/1.1" 200 154
192.168.1.10 - - [10/Nov/2009:17:08:47 +0800] "GET /test.jsp HTTP/1.1" 200 154
192.168.1.10 - - [10/Nov/2009:17:08:57 +0800] "GET /test_mysql.jsp HTTP/1.1" 404 997
192.168.1.10 - - [10/Nov/2009:17:17:43 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 2163
192.168.1.10 - - [10/Nov/2009:17:18:19 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 2163
192.168.1.10 - - [10/Nov/2009:17:18:22 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 3089
192.168.1.10 - - [10/Nov/2009:17:19:01 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 2163
192.168.1.10 - - [10/Nov/2009:17:19:39 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 2163
192.168.1.10 - - [10/Nov/2009:17:19:42 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 3089
192.168.1.10 - - [10/Nov/2009:17:19:43 +0800] "GET /test_mysql.jsp HTTP/1.1" 500 2163
作者: qingheliu    时间: 2009-11-11 10:18
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2