日期:2014-05-17  浏览次数:20674 次

搞了好久了.头都大了.各位帮帮忙吧.
错误:
2012-4-6 19:51:07 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
at mybean.StyleList.getBuffer(StyleList.java:36)
at org.apache.jsp.index_jsp._jspService(index_jsp.java:127)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:342)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:267)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:427)
at org.apache.coyote.ajp.AjpAprProtocol$AjpConnectionHandler.process(AjpAprProtocol.java:384)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1527)
at java.lang.Thread.run(Thread.java:619)
styleList.java:
Java code

/*
 * 网站JAVABEAN
 * 所有帖子分类列表.
 * 使用数据源连接.
 * 前后台共用JAVABEAN.
 */
package mybean;

import java.sql.*;

import mybean.DBConnSource;

public class StyleList {


    private String tableName;
    private Statement stmt;
    private ResultSet rs;
    private DBConnSource dbc; 
    
    public StyleList(){}
    
    public void setTableName(String n){
        this.tableName=n;
    }
    
    public StringBuffer getBuffer(){
        StringBuffer buffer=new StringBuffer();
        dbc=new DBConnSource("jdbc/myweb");
           try{            
            stmt=dbc.getStmt(); 
            }catch(Exception e){
                        System.out.print("不能连接到数据源"+e.toString());
            }
             
         try{    //这就是36行;
             String strSql="SELECT * FROM "+tableName; 
             rs = stmt.executeQuery(strSql);
             
             while(rs.next()){                    
                buffer.append("<a href='style.jsp?style="+rs.getString("style")+"' target=_blank>"+rs.getString("style")+"</a>");
                buffer.append("&nbsp;&nbsp;&nbsp;");
                }               
        }catch(SQLException e){
            System.out.print("结果集rs获取出错"+e.toString());
        }finally{
             try{               //关闭 ResultSet rs.
                     if(rs!=null){ 
                     rs.close();
                     }
                 }catch(SQLException ex){
                      System.out.print("关闭rs出错"+ex.toString());
                 }finally{
                         try{               // 关闭 Statement stmt. 
                                if(stmt!=null){