JavaExplore

一切像雾像雨又像风
posts - 19, comments - 45, trackbacks - 0, articles - 0

tomcat中jsp页面调用javabean

Posted on 2005-09-17 20:47 JavaExplore 阅读(1880) 评论(3)  编辑  收藏
1、变量、对象声明语法<%!.....%>
2、嵌入java语句语法<%......%>
3、调用javabean语法<jsp:useBean id="zong" scope="page" class="test.Hello"/>
     文件Hello.class位于目录web-inf\classes\test下,该jsp页面与文件夹web-inf位于同一目录下。
4、调用javabean的属性语法<jsp:getProperty id="zong" property="A"/>
   类Hello中要有方法getA();
5、javabean 的一般语法,构造函数为public,所有属性为private,每个属性对应get,set方法,boolean类型属性的对应get方法可以用is替换。

Feedback

# re: tomcat中jsp页面调用javabean  回复  更多评论   

2006-11-12 13:00 by dqf
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: /jc/regcklogin.jsp(7,0) The value for the useBean class attribute sist.DB is invalid.
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:510)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:375)
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: /jc/regcklogin.jsp(7,0) The value for the useBean class attribute sist.DB is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1174)
org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3305)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:198)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:295)
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:303)
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.17 logs.


--------------------------------------------------------------------------------

Apache Tomcat/5.5.17


帮我看看这个错误行吗?

# re: tomcat中jsp页面调用javabean  回复  更多评论   

2006-11-12 13:04 by dqf
jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<jsp:useBean id="con" scope="page" class="sist.DB" />

bean:
package sist;

import java.sql.*;
import java.io.*;
//import java.util.*;

public class DB {

private Connection conn = null;
private Statement drpStmt = null;
private ResultSet drpRst = null;
private int countInt = 0;
private String strDBError="";
boolean autoCommit;

public DB() {//构造函数开始
try{
//jdbc-odbc
Class.forName("org.gjt.mm.mysql.Driver");
//设置连接数据库信息
conn=DriverManager.getConnection("jdbc:mysql://localhost:3306/gordon?useUnicode=true&characterEncoding=gbk");

drpStmt = conn.createStatement();
}
catch(SQLException sqle){
countInt=-1;
strDBError=sqle.getMessage();
}
catch(java.lang.Exception e){
countInt=-2;
strDBError=e.getMessage();
}
}
//构造函数的结束
//构造函数的作用,当创建该类的对象时,将自动调用构造函数,并运行其中的方法,对于本程序来说,当创建本类的对象时,将自动连接数据库
//-------------------------------------------------------------------

public int getErrorCode(){

return countInt;

}

//-------------------------------------------------------------------



//-------------------------------------------------------------------

public String getErrorInfo(){

return strDBError;

}

//-------------------------------------------------------------------



//-------------------------------------------------------------------
//Q方法开始
//这个方法的返回值类型为结果集,主要完成数据库的查询操作,在使用的时候要向该方法传递SQL字符串
public ResultSet q(String queryString){
countInt=0;
strDBError="";
try{
drpRst = drpStmt.executeQuery(queryString);
countInt=1;
}catch(SQLException sqly){
countInt=-1;
strDBError+="Error occur while useing dataConn.exeQuery(queryString)!<p>The queryString is <p>" + queryString + "<p>The Error Information from DBMS锟斤拷<p>"+sqly.getMessage();
}catch(java.lang.Exception y){
countInt=-2;
strDBError+="<p>java.lang.Exception:"+y.getMessage();
}
return drpRst;
}
//-------------------------------------------------------------------



//-------------------------------------------------------------------
public int u(String updateString){
countInt=0;
strDBError="";
try{
countInt = drpStmt.executeUpdate(updateString);
}catch(SQLException sqlz){
countInt=-1;
strDBError="Error occur while using dataConn.exeUpdate()!The SQL is:<p>" + updateString + "<p>执行失败:<P>" + sqlz.getMessage();
}
return countInt;
}
//--------------------------------------------------------------------



public int getRowCount(String queryString){
countInt=0;
strDBError="";
ResultSet rs;
int nRowCount=0;
try{
rs=drpStmt.executeQuery("select count(*) from (" + queryString + ") as viewTempQueryString" );
while(rs.next()) nRowCount=rs.getInt(1);
}
catch(SQLException errGetRowCount){
countInt=-1;
strDBError+="Error occur while useing dataConn.getRowCount("+queryString+")! " + errGetRowCount.getMessage();
}catch(java.lang.Exception errOther){
countInt=-2;
strDBError+="" + errOther.getMessage();
}
return nRowCount;
}
//-----------------------------------------------------------

}//end of all


bean位置在C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\jc\WEB-INF\classes\sist里面

谢谢~~!

# re: tomcat中jsp页面调用javabean  回复  更多评论   

2008-04-02 21:18 by 啊啊啊
看看你的数据库驱动包是不是有错误。。。

只有注册用户登录后才能发表评论。


网站导航: