主题:用Eclipse写的JSP怎样调用JavaBean
supercrsky
[专家分:580] 发布于 2007-01-19 21:39:00
用Eclipse建的Web工程中写了个JavaBean请问源文件和生成的class文件应该放在哪?
我调用时,运行JSP页面说找不到我的JavaBean,具体怎么配置?
是不是JSP和.class文件在同一目录下,但我试了不行啊~
我的JavaBean:
import java.sql.*;
public class Conn
{
Connection con = null;
public Connection getCon()
{
try
{
new sun.jdbc.odbc.JdbcOdbcDriver();
con = DriverManager.getConnection("jdbc:odbc:test","sa","");
} catch (Exception e) {
e.toString();
}
return con;
}
}
我的JSP:
<%@ page language="java" contentType="text/html; charset=gbk"
pageEncoding="gbk"%>
<%@ page import = "java.sql.*" %>
<jsp:useBean id = "sel" scope = "page" class = "Conn" />
<%
Connection conn = sel.getCon();
Statement stmt= conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from Customers");
while(rs.next())
{
out.println(rs.getString(1));
}
%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
</body>
</html>
回复列表 (共5个回复)
沙发
supercrsky [专家分:580] 发布于 2007-01-19 22:43:00
这是异常信息
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: 4 in the jsp file: /JavaBean.jsp
Generated servlet error:
Conn cannot be resolved to a type
An error occurred at line: 4 in the jsp file: /JavaBean.jsp
Generated servlet error:
Conn cannot be resolved to a type
An error occurred at line: 4 in the jsp file: /JavaBean.jsp
Generated servlet error:
Conn cannot be resolved to a type
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:512)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 4 in the jsp file: /JavaBean.jsp
Generated servlet error:
Conn cannot be resolved to a type
An error occurred at line: 4 in the jsp file: /JavaBean.jsp
Generated servlet error:
Conn cannot be resolved to a type
An error occurred at line: 4 in the jsp file: /JavaBean.jsp
Generated servlet error:
Conn cannot be resolved to a type
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:84)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:328)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:414)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:297)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:276)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:264)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:563)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:305)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.20 logs.
板凳
adler [专家分:890] 发布于 2007-01-19 22:55:00
bean写在src下,jsp写在webroot下
3 楼
linxuanxu [专家分:9360] 发布于 2007-01-19 23:05:00
1\ Class 文件放在 WEB-INF\classes 网站相对路径哦
4 楼
supercrsky [专家分:580] 发布于 2007-01-19 23:25:00
谢谢,已经解决~
5 楼
yexin218 [专家分:4070] 发布于 2007-01-20 10:22:00
为了方便,一般bean放在自己的包中,便于管理。
我来回复