
配置好 jsp 服务器了,现在是检验服务器可用性。
也就是 编写一个简单的 jsp 来连接数据库,看看是否成功。
要测试jsp连接mysql数据库 首先要清楚自己服务器的一些软件的存放位置
例如 我的apache软件,页面存放的路径如下:
/usr/local/apache2/htdocs/
我的Tomcat 安装目录 如下 :
Tomcat目录是/usr/local/tomcat
因为我们要借助一个jar 包,才能让jsp网页成功连接mysql数据库。
mysql-connector-java-5.1.10-bin.jar
这就是我使用的包,目前最新版本的,大家可以到 http://www.sun.com 官方下载。
我也会到文章最后 提供下载。
好有了连接包, 我们还需要一个 jsp 测试页面。
这是我的测试页面 test_mysql.jsp
代码比较简单 就是一个 连接数据库代码。。。。
下面把 2个文件 上传到 CentOS 5.4 Linux 服务器上去
好,已经把2个文件 下载到 服务器上面去了。
mv mysql-connector-java-5.1.10-bin.jar /usr/local/tomcat/lib/
把 mysql-connector-java-5.1.10-bin.jar 放到 tomcat 目录 lib 下面去
我使用的 mysql 是 6.0 版本。其他版本也许目录不一样吧。
可以看到 lib 这个目录下都是 jar 存放的地方
然后 我们就 访问一下 测试页面 test_mysql.jsp
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
出现错误, 说没有 找到 mysql-connector-java-5.1.10-bin.jar 。。。。
检查一下 这个包 的确存在 /usr/local/tomcat/lib/ 目录下。
把 tomcat 重启一下吧。
进入 /usr/local/tomcat/bin 目录 输入
关闭 tomcat 命令: ./shutdown.sh
再启动 : ./startup.sh
====================
然后再刷新页面
这次 出现了 OK 页面, 这可能是我以前的历史, 我再刷新一下
connent mysql error:java.sql.SQLException: Access denied for user 'mysql'@'localhost' (using password: YES)
出现了错误, 提示 这是 密码错误吧 。
因为jsp页面是网上找到的,做了一些修改,忘记改密码了。
修改好 jsp 页面 的用户名 密码 还有数据库 代码 后 保存再 刷新页面
这样说明 正常 连接 mysql 数据库了。。。。。好了 测试到这里 8
11月 10th, 2009 at 17:28:03 #yzhkpli
我改好了test_mysql.jsp里面mysql服务的root链接密码
但是依旧无法访问http://httpserver_ip/test_mysql.jsp
报告:
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.
[回复]
adminreply on 2009-11-12 10:05:01:
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
================
很有可能是 你没有安装 mysql-connector-java-5.1.10-bin.jar 连接mysql数据库jar包, 注意检查 包放的位置。
01月 17th, 2010 at 10:30:38 #iteasier
博主你好!首先感谢的你教程,我已在centos5.4上成功搭建了jsp环境,并打开test_mysql.jsp出现OK,我想应该是成功了,但我在安装国内的jeecms时,在连接并新建数据库时出现了以下错误提示:
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: 31 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
28: String webXmlTo = "/WEB-INF/web.xml";
29: //������ݿ�
30: if ("true".equals(isCreateDb)) {
31: Install.createDb(dbHost, dbPort, dbName, dbUser, dbPassword);
32: } else {
33: Install.changeDbCharset(dbHost, dbPort, dbName, dbUser, dbPassword);
34: }
An error occurred at line: 33 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
30: if ("true".equals(isCreateDb)) {
31: Install.createDb(dbHost, dbPort, dbName, dbUser, dbPassword);
32: } else {
33: Install.changeDbCharset(dbHost, dbPort, dbName, dbUser, dbPassword);
34: }
35: //������
36: if ("true".equals(isCreateTable)) {
An error occurred at line: 38 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
35: //������
36: if ("true".equals(isCreateTable)) {
37: String sqlPath = application.getRealPath(dbFileName);
38: List sqlList = Install.readSql(sqlPath);
39: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
40: sqlList);
41: }
An error occurred at line: 39 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
36: if ("true".equals(isCreateTable)) {
37: String sqlPath = application.getRealPath(dbFileName);
38: List sqlList = Install.readSql(sqlPath);
39: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
40: sqlList);
41: }
42: //��ʼ�����
An error occurred at line: 45 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
42: //��ʼ�����
43: if ("true".equals(isInitData)) {
44: String initPath = application.getRealPath(initFileName);
45: List initList = Install.readSql(initPath);
46: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
47: initList);
48: }
An error occurred at line: 46 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
43: if ("true".equals(isInitData)) {
44: String initPath = application.getRealPath(initFileName);
45: List initList = Install.readSql(initPath);
46: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
47: initList);
48: }
49: //��������
An error occurred at line: 50 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
47: initList);
48: }
49: //��������
50: Install.updateConfig(dbHost, dbPort, dbName, dbUser, dbPassword,
51: domain, cxtPath, port);
52: //������ݿ������ļ�
53: String dbXmlPath = application.getRealPath(dbXmlFileName);
An error occurred at line: 54 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
51: domain, cxtPath, port);
52: //������ݿ������ļ�
53: String dbXmlPath = application.getRealPath(dbXmlFileName);
54: Install
55: .dbXml(dbXmlPath, dbHost, dbPort, dbName, dbUser,
56: dbPassword);
57: //����web.xml
An error occurred at line: 60 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
57: //����web.xml
58: String webXmlFromPath = application.getRealPath(webXmlFrom);
59: String webXmlToPath = application.getRealPath(webXmlTo);
60: Install.webXml(webXmlFromPath, webXmlToPath);
61: %>
62:
63: <table width="600" align="center"
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:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
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.18 logs.
请问是什么原因造成,我试了很多次都没成功。
[回复]
01月 17th, 2010 at 17:59:57 #iteasier
博主你好!首先非常感谢你们的教程,我成功的在centos5.4下搭建了jsp服务器,并测试test_mysql.jsp成功,但我在安装国内的jeecms(jsp内容管理系统)时出现以下错误:
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: 31 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
28: String webXmlTo = "/WEB-INF/web.xml";
29: //������ݿ�
30: if ("true".equals(isCreateDb)) {
31: Install.createDb(dbHost, dbPort, dbName, dbUser, dbPassword);
32: } else {
33: Install.changeDbCharset(dbHost, dbPort, dbName, dbUser, dbPassword);
34: }
An error occurred at line: 33 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
30: if ("true".equals(isCreateDb)) {
31: Install.createDb(dbHost, dbPort, dbName, dbUser, dbPassword);
32: } else {
33: Install.changeDbCharset(dbHost, dbPort, dbName, dbUser, dbPassword);
34: }
35: //������
36: if ("true".equals(isCreateTable)) {
An error occurred at line: 38 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
35: //������
36: if ("true".equals(isCreateTable)) {
37: String sqlPath = application.getRealPath(dbFileName);
38: List sqlList = Install.readSql(sqlPath);
39: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
40: sqlList);
41: }
An error occurred at line: 39 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
36: if ("true".equals(isCreateTable)) {
37: String sqlPath = application.getRealPath(dbFileName);
38: List sqlList = Install.readSql(sqlPath);
39: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
40: sqlList);
41: }
42: //��ʼ�����
An error occurred at line: 45 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
42: //��ʼ�����
43: if ("true".equals(isInitData)) {
44: String initPath = application.getRealPath(initFileName);
45: List initList = Install.readSql(initPath);
46: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
47: initList);
48: }
An error occurred at line: 46 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
43: if ("true".equals(isInitData)) {
44: String initPath = application.getRealPath(initFileName);
45: List initList = Install.readSql(initPath);
46: Install.createTable(dbHost, dbPort, dbName, dbUser, dbPassword,
47: initList);
48: }
49: //��������
An error occurred at line: 50 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
47: initList);
48: }
49: //��������
50: Install.updateConfig(dbHost, dbPort, dbName, dbUser, dbPassword,
51: domain, cxtPath, port);
52: //������ݿ������ļ�
53: String dbXmlPath = application.getRealPath(dbXmlFileName);
An error occurred at line: 54 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
51: domain, cxtPath, port);
52: //������ݿ������ļ�
53: String dbXmlPath = application.getRealPath(dbXmlFileName);
54: Install
55: .dbXml(dbXmlPath, dbHost, dbPort, dbName, dbUser,
56: dbPassword);
57: //����web.xml
An error occurred at line: 60 in the jsp file: /jeecms/install/install_setup.jsp
Install cannot be resolved
57: //����web.xml
58: String webXmlFromPath = application.getRealPath(webXmlFrom);
59: String webXmlToPath = application.getRealPath(webXmlTo);
60: Install.webXml(webXmlFromPath, webXmlToPath);
61: %>
62:
63: <table width="600" align="center"
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:423)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:317)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:282)
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.18 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.18
请问是什么原因?
[回复]
adminreply on 2010-02-26 10:38:42:
这可能是你安装时候出现的问题吧, 看看那个系统的说明,
可能是一些参数没有修改好, 例如一些连接数据库使用的用户名和密码,等等,
或者先要建立好数据库 再进行安装。