JavaExplore

          一切像霧像雨又像風
          posts - 19, comments - 45, trackbacks - 0, articles - 0

          tomcat中jsp頁面調(diào)用javabean

          Posted on 2005-09-17 20:47 JavaExplore 閱讀(1897) 評論(3)  編輯  收藏
          1、變量、對象聲明語法<%!.....%>
          2、嵌入java語句語法<%......%>
          3、調(diào)用javabean語法<jsp:useBean id="zong" scope="page" class="test.Hello"/>
               文件Hello.class位于目錄web-inf\classes\test下,該jsp頁面與文件夾web-inf位于同一目錄下。
          4、調(diào)用javabean的屬性語法<jsp:getProperty id="zong" property="A"/>
             類Hello中要有方法getA();
          5、javabean 的一般語法,構(gòu)造函數(shù)為public,所有屬性為private,每個屬性對應(yīng)get,set方法,boolean類型屬性的對應(yīng)get方法可以用is替換。

          Feedback

          # re: tomcat中jsp頁面調(diào)用javabean  回復(fù)  更多評論   

          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頁面調(diào)用javabean  回復(fù)  更多評論   

          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() {//構(gòu)造函數(shù)開始
          try{
          //jdbc-odbc
          Class.forName("org.gjt.mm.mysql.Driver");
          //設(shè)置連接數(shù)據(jù)庫信息
          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();
          }
          }
          //構(gòu)造函數(shù)的結(jié)束
          //構(gòu)造函數(shù)的作用,當創(chuàng)建該類的對象時,將自動調(diào)用構(gòu)造函數(shù),并運行其中的方法,對于本程序來說,當創(chuàng)建本類的對象時,將自動連接數(shù)據(jù)庫
          //-------------------------------------------------------------------

          public int getErrorCode(){

          return countInt;

          }

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



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

          public String getErrorInfo(){

          return strDBError;

          }

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



          //-------------------------------------------------------------------
          //Q方法開始
          //這個方法的返回值類型為結(jié)果集,主要完成數(shù)據(jù)庫的查詢操作,在使用的時候要向該方法傳遞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>執(zhí)行失敗:<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頁面調(diào)用javabean  回復(fù)  更多評論   

          2008-04-02 21:18 by 啊啊啊
          看看你的數(shù)據(jù)庫驅(qū)動包是不是有錯誤。。。

          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 凤山县| 昆明市| 亳州市| 噶尔县| 平远县| 卢氏县| 樟树市| 临潭县| 襄樊市| 蓬溪县| 阿荣旗| 明水县| 含山县| 宜章县| 临海市| 南康市| 新泰市| 阿鲁科尔沁旗| 巴楚县| 卓尼县| 南澳县| 沂水县| 启东市| 阿巴嘎旗| 绥芬河市| 恩平市| 汽车| 都匀市| 汪清县| 同心县| 高唐县| 唐海县| 子洲县| 余姚市| 洞口县| 墨竹工卡县| 肥西县| 江山市| 惠水县| 镇康县| 板桥市|