在本地做好的JSP+MYSQL,上传到远程空间后打开时报错.
2011-8-8 9:14:14 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:113)
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.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:190)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:291)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:769)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:698)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:891)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:690)
at java.lang.Thread.run(Thread.java:619)

解决方案 »

  1.   

    我的数据源配置:
    ROOT/META-INF/context.xml:
    <Context>
    <Resource
                 name="jdbc/myweb"
                 type="javax.sql.DataSource"
                 auth="Container"
                 username="*****" //这里和远程空间的数据库文件名相同
                 password="*****"
                 driverClassName="com.mysql.jdbc.Driver"
                 maxIdle="2"
                 maxWait="5000"
                 url="jdbc:MySQL://localhost:3306/study?characterEncoding=GBK"
                 maxActive="4"
    <!--Default set of monitored resources -->
    <WatchedResource>Web-INF/web.xml</WatchedResource>
    <Context>
    ROOT/lib/web.xml:
    <!-- DataSource Begin -->
    <resource-ref>
    <description>Datasource</description>
    <res-ref-name>jdbc/myweb</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>
    <!-- DataSource end -->
      

  2.   


    java.lang.NullPointerException
    at mybean.StyleList.getBuffer(StyleList.java:36)

    自己跟踪下么。
      

  3.   

    另外,我自己写了一个远程测试文件:
    <%@ page contentType="text/html; charset=GBK" %>
    <%@ page language="java" %>
    <%@ page import="com.mysql.jdbc.Driver" %>
    <%@ page import="java.sql.*" %>
    <HTML>
    <head>
    <title>数据库远程测试</title>
    </head>
    <BODY>
    <%
    //驱动程序名
    String driverName="com.mysql.jdbc.Driver";
    //远程空间数据库用户名
    String username="*****";
    //密码
    String password="*****";
    //数据库名
    String dbName="study";
    //表名
    String tableName="adver";
    //连接字符串
    String url="jdbc:MySQL://localhost/"+dbName+"?useUnicode=true&characterEncoding=GBK";
    try{
       //加载驱动程序
       Class.forName("com.mysql.jdbc.Driver");
       //建立同数据库的连接对象
       Connection connection=DriverManager.getConnection(url,username,password);
       Statement statement = connection.createStatement();
       String sql="SELECT * FROM "+tableName;
       //发送要执行的SQL语句
       ResultSet rs = statement.executeQuery(sql);
       out.print("数据库连接成功<BR>");
      rs.afterLast();
       while(rs.previous())
          {
           out.print(rs.getInt(1));
           out.print(rs.getString("city"));
           out.print(rs.getString("style"));
           out.print(rs.getString("title"));
           out.print(rs.getString("content"));
           out.print(rs.getString("chec"));
           out.print("<br/>");
          }
       rs.close();
       statement.close();
       connection.close();
       }
    catch(SQLException e)
       {
        out.print(e.toString());
       }
    %>
    </body>
    </html>
    这一个文件是可以正常显示的.
      

  4.   

    刚才我又测试一下.我在远程空间的数据库里新添加一条数据.再打开测试文件.发现数据更新了.证明这份文件真的可以正常显示.那我的文件里这一句
    String url="jdbc:MySQL://localhost/"+dbName+"?useUnicode=true&characterEncoding=GBK"
    难道不用修改就可以用了?本来是忘了改就传上去了.现在却歪打正着了.
    ---------------------------
    回2楼.跟踪怎么做呀?我学JSP时间不长.很多东西不懂的.