一个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) 

解决方案 »

  1.   

    楼主的机器有安装相应的软件并配置吗?
    比如java,mysql等? 另外检查Apache的配置是否正确。
      

  2.   

    jdbc:mysql://localhost/hj?useUnicode=true&characterEncoding=utf-8", 
    你的端口呢???
      

  3.   

    jdbc:mysql://localhost/hj?useUnicode=true&characterEncoding=utf-8",
    端口
    另外,楼主请确认你的环境配置和你朋友机子上的全部相同么,包括数据库密码,用户名等等
      

  4.   

    MySQL数据库 正确的连接方法:
    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);
    如果你驱动加载好了,就没有问题,这一直是这么用来的,没有问题.
      

  5.   

    缺少com.mchange.v2.c3p0.DataSources 。可能你朋友把它放在classes文件夹下,而你只拷了src文件夹下的内容。
    所以你的机器缺少一些包。检查下你们classes文件夹下的内容。
      

  6.   

    6楼说对了,找不到DataSources这个类
      

  7.   

    mysql的端口可以省略的。应该不是这个问题。
      

  8.   

    Only a type can be imported. com.mchange.v2.c3p0.DataSources
    从这句话可看出只能引入一个类型就是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文件
      

  9.   

    一般情况下,javax.sql.DataSource是能被识别的,多半应是com.mchange.v2.c3p0.DataSources不能识别吧
      

  10.   

    正确安装所需软件是前提
    (如果只是在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)
        {
        }
    // 完成
      

  11.   

    检查你的开发环境,JDK版本是否与你朋友那里一致。
      

  12.   

    exception  
    org.apache.jasper.JasperException: Unable to compile class for JSP:  不能编译 jsp, 环境问题
      

  13.   

    1、是的,那个包,可能是你朋友及其里面别的项目里面的,而你呢,可能是直接调用的,所以报错
    2、看看你的驱动装对版本没有,端口设置,用户名和密码是否真确
    3.看看你的机器的mysql服务是不是启动起来。