如何在JSP中调用自己定义的类
我的文件目录为:
test/
----WEB-INF/
--------lib/
------------mysql-connector-java-5.1.7-bin.jar
--------classes/
------------ConnMysql.class
----index.jsp
ConnMysql.java
index.jsp
但是打开index.jsp时显示错误
应该是说找不到ConnMysql这个类吧,请问各位高手们应该怎么做才能解决这个问题
test/
----WEB-INF/
--------lib/
------------mysql-connector-java-5.1.7-bin.jar
--------classes/
------------ConnMysql.class
----index.jsp
ConnMysql.java
import java.sql.*;
public class ConnMysql {
public static Connection getConnection(){
try {
Class.forName("com.mysql.jdbc.Driver");
String url ="jdbc:mysql://localhost:3306/test?user=root&password=root&useUnicode=true&characterEncoding=GBK";
return DriverManager.getConnection(url);
} catch (Exception e) {
System.out.print(e.getMessage());
return null;
}
}
}
index.jsp
<%@page import="java.sql.*" %>
<%@page import="ConnMysql" %>
<%
Connection conn = null;
Statement stat = null;
ResultSet rs = null ;
try{
conn = ConnMysql.getConnection();
stat = conn.createStatement();
rs = stat.executeQuery("SELECT * FROM test");
while (rs.next()){
out.print(rs.getString("id") + ":");
out.println(rs.getString("name"));
}
}catch(Exception e){
out.println(e.getMessage());
}
%>
但是打开index.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: 7 in the generated java file
The import ConnMysql cannot be resolved
An error occurred at line: 9 in the jsp file: /index.jsp
ConnMysql cannot be resolved
6: ResultSet rs = null ;
7:
8: try{
9: conn = ConnMysql.getConnection();
10: stat = conn.createStatement();
11: rs = stat.executeQuery("SELECT * FROM test");
12: while (rs.next()){
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:349)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:314)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:592)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
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.29 logs.
--------------------------------------------------------------------------------
Apache Tomcat/6.0.29
应该是说找不到ConnMysql这个类吧,请问各位高手们应该怎么做才能解决这个问题
...全文
相关推荐
JSP自定义标签
详细讲解JSP自定义标签的相关知识及创建过程。
学习jsp自定义标签
这是我总结的jsp标签的相关知识,希望对像我这样的初学者有点益处!
由浅到深详细讲解JSP自定义标签
由浅到深详细讲解JSP自定义标签
jsp自定义标签[归纳].pdf
jsp自定义标签[归纳].pdf
Jsp自定义标签和方法详解
Jsp自定义标签和方法详解 首先是要有一个标签处理类,标签处理类可以直接实现Tag接口,也可以继承Java中已经实现了的TagSupport这个类,TagSupport也是继承自Tag接口的,它内部已经对Tag接口进行了实现,一般是继承TagSupport类,之后是重写父类的doStartTag和doEndTag方法, 对于开始标签来说返回值主要有EVAL_BODY_INCLUDE和SKIP_BODY,前者表示执行标签体,后者表示略过标签体; 对于结束标签的返回值主要有两种EVAL_PAGE和SKIP_PAGE,前者表示继续执行结束标签以后的内容,后者表示忽略结束标签以后的内容;另外,在继承


Web 开发
