-3

こんにちは、Java/jsp 開発の初心者です。

jspファイルが前のページから受け取ったパラメータに応じて、データベースに接続しようとしています。私のプログラムは、単一のDBに接続すると機能します

 try {
        InputStream in = getServletContext().getResourceAsStream("/WEB-INF/db.properties");
        properties.load(in);
        connString = properties.getProperty("db_conn").toString();
        connUser = properties.getProperty("db_user").toString();
        connPass = properties.getProperty("db_pass").toString();
        bPath = properties.getProperty("exec_path").toString();
        in.close();
      } catch (IOException ex) {
        System.out.println(ex);
      }

および db.properties ファイルには次が含まれます

      db_conn=jdbc:oracle:thin:@33.333.3.33:3333:DKSE1
      db_user=guest
      db_pass=guestpw

私の試み:

 String userinfo = request.getParameter("userinfo");
 try {
        InputStream in = getServletContext().getResourceAsStream("/WEB-INF/db.properties");
        properties.load(in);
        db_conn = userinfo + "_conn";
        db_user = userinfo + "_user";
        db_pass = userinfo + "_pass";
        connString = properties.getProperty(db_conn).toString();
        connUser = properties.getProperty(db_user).toString();
        connPass = properties.getProperty(db_pass).toString();
        bPath = properties.getProperty("exec_path").toString();
        in.close();
      } catch (IOException ex) {
        System.out.println(ex);
      }

      try {
        // --- Required database stuff ---
        DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
        Connection conn = DriverManager.getConnection(connString, connUser, connPass);
        Statement stmt = conn.createStatement();
        More codes....
       }

デシベルのプロパティ

       guest_conn=jdbc:oracle:thin:@33.333.3.33:3333:DKSE1
       guest_user=guest
       guest_pass=guestpw

       user_conn=jdbc:oracle:thin@11.222.3.33:4444:ESMZ1
       user_user=user
       user_pass=upw1

       user1_conn=jdbc:oracle:thin@11.11.1.11:1111:GEPD1
       user1_user=user1
       user1_pass=upw1 

       batch_exec_path = ${SERVER_DIR}

スタックトレース

Nov 30, 2012 9:03:55 AM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [/dashboard] threw exception [An exception occurred processing JSP page /alpharunBatch.jsp at line 106

103:             db_conn = userinfo + "_conn";
104:             db_user = userinfo + "_user";
105:             db_pass = userinfo + "_pass";
106:             connString = properties.getProperty(db_conn).toString();
107:             connUser = properties.getProperty(db_user).toString();
108:             connPass = properties.getProperty(db_pass).toString();
109:             bPath = properties.getProperty("exec_path").toString();


Stacktrace:] with root cause
java.lang.NullPointerException
    at org.apache.jsp.alpharunBatch_jsp._jspService(alpharun_jsp.java:192)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

私は根本的に間違ったことをしていますか?ご協力いただきありがとうございます!

4

1 に答える 1

0

テストのために以下を試してください:

それを変える

InputStream in = getServletContext().getResourceAsStream("/WEB-INF/db.properties");

InputStream in = getServletContext().getResourceAsStream("db.properties");

プロパティをクラスパスフォルダー(src)に配置します

さらに変更

properties.getProperty("exec_path").toString();

properties.getProperty("batch_exec_path").toString();
于 2012-11-30T14:31:48.800 に答える