一个JSP设计
这个设计在朋友的机子上没有任何问题 通过了所有的测试 但是拿回我电脑后 连接就老是出问题
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: 8 in the generated java file
Only a type can be imported. com.mchange.v2.c3p0.DataSources resolves to a package An error occurred at line: 5 in the jsp file: /zxdc/common/inc.jsp
DataSources cannot be resolved
2: <%@page import="com.mchange.v2.c3p0.DataSources,javax.sql.DataSource"%>
3: <%
4: Class.forName("org.gjt.mm.mysql.Driver").newInstance();
5: DataSource ds = DataSources
6: .unpooledDataSource(
7: "jdbc:mysql://localhost/hj?useUnicode=true&characterEncoding=utf-8",
8: "root", "root");
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:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
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)
这个设计在朋友的机子上没有任何问题 通过了所有的测试 但是拿回我电脑后 连接就老是出问题
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: 8 in the generated java file
Only a type can be imported. com.mchange.v2.c3p0.DataSources resolves to a package An error occurred at line: 5 in the jsp file: /zxdc/common/inc.jsp
DataSources cannot be resolved
2: <%@page import="com.mchange.v2.c3p0.DataSources,javax.sql.DataSource"%>
3: <%
4: Class.forName("org.gjt.mm.mysql.Driver").newInstance();
5: DataSource ds = DataSources
6: .unpooledDataSource(
7: "jdbc:mysql://localhost/hj?useUnicode=true&characterEncoding=utf-8",
8: "root", "root");
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:308)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
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)
解决方案 »
- 用jspsmartuplod在做文件上传时怎么删除上传的本地文件文件
- jpa查询语句
- 用java做网站,不是用jsp,那是什么?急!我是java初学者,请大家帮忙指导一下。谢谢啦!
- 散分!求源代码,谁有JSP写的“进销存管理系统”的源代码啊??急急急!
- 实例对象共享问题?
- 初学关于javabean路径的问题(在线等待)
- 如何编写sql精确匹配某字段中的特定字符?
- 【求助】 mysql 中文乱码
- 我有个TIF的问题,问了很久都没有人解决,请各位高手帮忙!帮忙!(楼主有空帮忙一下吗?)
- 请问现在深入学习servlet还有没有必要
- SSH和mysql中的中文乱码问题
- 在JSP中如何限制时间查询条件,谢谢!
比如java,mysql等? 另外检查Apache的配置是否正确。
你的端口呢???
端口
另外,楼主请确认你的环境配置和你朋友机子上的全部相同么,包括数据库密码,用户名等等
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
String url ="jdbc:mysql://localhost/myDB?user=soft&password=soft1234&useUnicode=true&characterEncoding=utf-8"
//myDB为数据库名 ,此例中用户名为soft,密码为:soft1234,编码方式为utf-8
Connection conn= DriverManager.getConnection(url);
如果你驱动加载好了,就没有问题,这一直是这么用来的,没有问题.
所以你的机器缺少一些包。检查下你们classes文件夹下的内容。
从这句话可看出只能引入一个类型就是com.mchange.v2.c3p0的DateSources类org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: 5 in the jsp file: /zxdc/common/inc.jsp
从这两句话可看出,在inc.jsp文件里面你引入了com.mchange.v2.c3p0.DataSources类和javax.sql.DataSource类,但它只能识别前者
所以楼主就干脆引入两个import吧
<%@page import="com.mchange.v2.c3p0.DataSources">
<%@page import="javax.sql.DataSource">
报错的原因应该是,系统不能识别javax.sql.DataSource类,从而不能编译inc.jsp生成的inc_jsp.java文件
(如果只是在JSP中连接MySQL的话,复制 MySQL 的 JDBC 驱动到 Tomcat 的 LIB 目录)
(否则可以将 Mysql 的 jdbc 加入到 jre/jdk 的 lib)1.将 mysql 的驱动文件mysql.jar复制到tomcat/lib录2.编辑 web 应用中的目录 META-INF/context.xml 文件,内容如下<Context path="/webapp" URIEncoding="UTF-8">
<Resource name="jdbc/myjdbc"
auth="Container"
description="DB Connection"
driverClassName="com.mysql.jdbc.Driver"
maxActive="500"
maxIdle="30"
maxWait="10000"
type="javax.sql.DataSource"
username="sqluser1"
password="123456"
url="jdbc:mysql://192.168.1.2:3306/mydb?autoReconnect=true"
/>
</Context>webapp:你的应用名称mydb:MySQL 内 Database 的名称com.mysql.jdbc.Driver:所使用的驱动,来自倒入的 mysql 的 jar 文件.编辑 web 应用中的目录 WEB-INF/web.xml 内容如下 <resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/myjdbc</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>至此,针对 MySQL 的数据连结池配置完成import java.sql.*;
import javax.sql.*; ...... Connection con;
Statement stmt;
ResultSet rs; try
{
// 连接数据库
Context ctx = new InitialContext ();
DataSource ds = (DataSource) ctx.lookup ("java:comp/env/jdbc/myjdbc");
con = ds.getConnection ();
// 创建 JDBC 申明
stmt = con.createStatement (); try
{ // SQL 命令构建 String SqlCmdText = "select * from message_text"; // 执行SQL命令 rs = stmt.executeQuery (sqlCmdSelect); // 遍历所有记录 where ( rs.next() { String OutText = rs.getString("fieldname"); ...... ......
} // 资源释放
if ( rs != null )
{
rs.close ();
}
}
catch (Exception e)
{
} // 资源释放 if (stmt != null)
{
stmt.close ();
}
if (con != null)
{
con.close ();
}
}
catch (Exception e)
{
}
// 完成
org.apache.jasper.JasperException: Unable to compile class for JSP: 不能编译 jsp, 环境问题
2、看看你的驱动装对版本没有,端口设置,用户名和密码是否真确
3.看看你的机器的mysql服务是不是启动起来。