Nome non è associato in questo contesto

Vedo che questa domanda è stata sollevata diverse volte e ho esaminato tutte queste domande. Ma non riesco ancora a risolvere il mio problema.

Qualcuno potrebbe aiutarmi a individuare ciò che sto facendo male?

Ottengo il seguente messaggio di errore quando provo ad accedere a database.jsp:

HTTP Status 500 - An exception occurred processing JSP page /database.jsp at line 24 type Exception report message An exception occurred processing JSP page /database.jsp at line 24 description The server encountered an internal error that prevented it from fulfilling this request. exception org.apache.jasper.JasperException: An exception occurred processing JSP page /database.jsp at line 24 21: <% 22: Context init = new InitialContext(); 23: Context env = (Context) init.lookup("java:/comp/env/"); 24: DataSource data = (DataSource) env.lookup("jdbc/mydb"); 25: Connection conn = data.getConnection(); 26: Statement stmt = conn.createStatement(); 27: Stacktrace: org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) root cause javax.servlet.ServletException: javax.naming.NameNotFoundException: Name [jdbc/mydb] is not bound in this Context. Unable to find [jdbc]. org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:916) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:845) org.apache.jsp.database_jsp._jspService(database_jsp.java:185) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:727) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 

Ecco alcune informazioni sulla mia installazione: Il mio computer è in esecuzione su Mac OS X. Il server Web è Tomcat versione 7.0.52, installato in /Users/username/Dropbox/Server/apache-tomcat-7.0.52. Sto cercando di eseguire Derby 10.10.1.1 come database incorporato. Ho copiato derby.jar sotto la cartella /Users/username/Dropbox/Server/apache-tomcat-7.0.52/lib. Ho scritto quanto segue nel mio file PATH (non sono sicuro che sia rilevante):

 export DERBY_HOME=/Users/username/Dropbox/Server/apache-tomcat-7.0.52/lib export PATH=$PATH:$DERBY_HOME/bin 

Ecco il contenuto del file web.xml:

   Welcome to Tomcat  Welcome to Tomcat  DB Connection jdbc/mydb javax.sql.DataSource Container    

context.xml

     WEB-INF/web.xml  

server.xml

                               

Infine, ecco la pagina database.jsp:

   Quote Query   

retrieve stock quotes

Choose Ticker(s):

AAPL MSFT
<% Context init = new InitialContext(); Context env = (Context) init.lookup("java:/comp/env/"); DataSource data = (DataSource) env.lookup("jdbc/mydb"); Connection conn = data.getConnection(); Statement stmt = conn.createStatement(); String sqlStr = "SELECT * FROM Quotes WHERE Ticker IN ("; sqlStr += "'" + tickers[0] + "'"; // First ticker for (int i = 1; i
Ticker Date PriceOpen PriceHigh PriceLow PriceClose Volume PriceAdjClose
<input type="checkbox" name="id" value=""> $ $

<a href="https://stackoverflow.com/questions/22545169/name-jdbc-mydb-is-not-bound-in-this-context/">

Back

Login

 Mar 21, 2014 7:57:26 AM org.apache.catalina.core.AprLifecycleListener init INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /Users/lcazarre/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. Mar 21, 2014 7:57:26 AM org.apache.tomcat.util.digester.SetPropertiesRule begin WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'debug' to '0' did not find a matching property. Mar 21, 2014 7:57:28 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["http-bio-8080"] Mar 21, 2014 7:57:28 AM org.apache.coyote.AbstractProtocol init INFO: Initializing ProtocolHandler ["ajp-bio-8009"] Mar 21, 2014 7:57:28 AM org.apache.catalina.startup.Catalina load INFO: Initialization processed in 3227 ms Mar 21, 2014 7:57:28 AM org.apache.catalina.core.StandardService startInternal INFO: Starting service Catalina Mar 21, 2014 7:57:28 AM org.apache.catalina.core.StandardEngine startInternal INFO: Starting Servlet Engine: Apache Tomcat/7.0.52 Mar 21, 2014 7:57:28 AM org.apache.catalina.realm.UserDatabaseRealm startInternal SEVERE: Exception looking up UserDatabase under key UserDatabase javax.naming.NameNotFoundException: Name [UserDatabase] is not bound in this Context. Unable to find [UserDatabase]. at org.apache.naming.NamingContext.lookup(NamingContext.java:819) at org.apache.naming.NamingContext.lookup(NamingContext.java:167) at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:253) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201) at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Catalina.start(Catalina.java:689) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455) Mar 21, 2014 7:57:28 AM org.apache.catalina.realm.CombinedRealm startInternal SEVERE: Failed to start "org.apache.catalina.realm.UserDatabaseRealm/1.0" realm org.apache.catalina.LifecycleException: Failed to start component [Realm[UserDatabaseRealm]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201) at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:443) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) at org.apache.catalina.startup.Catalina.start(Catalina.java:689) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455) Caused by: org.apache.catalina.LifecycleException: No UserDatabase component found under key UserDatabase at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:262) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 17 more Mar 21, 2014 7:57:31 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/docs Mar 21, 2014 7:57:32 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/examples Mar 21, 2014 7:57:33 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/host-manager Mar 21, 2014 7:57:33 AM org.apache.catalina.startup.HostConfig deployDirectory INFO: Deploying web application directory /Users/lcazarre/Dropbox/Work/MS50/COMSM0104/Server/apache-tomcat-7.0.52/webapps/manager Mar 21, 2014 7:57:34 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["http-bio-8080"] Mar 21, 2014 7:57:34 AM org.apache.coyote.AbstractProtocol start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Mar 21, 2014 7:57:34 AM org.apache.catalina.startup.Catalina start INFO: Server startup in 6321 ms 

Grazie, LC

È necessario un ResourceLink nel file META-INF/context.xml per rendere la risorsa globale disponibile per l’applicazione Web.

   

Per coloro che usano Tomcat con Bitronix, questo risolverà il problema:

L’errore indica che non è stato ansible trovare alcun gestore per l’origine dati ‘jdbc / mydb’ , quindi è necessario assicurarsi che il server tomcat si riferisca ai file di configurazione di bitronix secondo necessità.

Nel caso in cui si utilizzino i file btm-config.properties e resources.properties per configurare l’origine dati, specificare questi due argomenti JVM in tomcat:

(se li hai già usati, assicurati che i tuoi riferimenti siano corretti):

  • btm.root
  • bitronix.tm.configuration

per esempio

 -Dbtm.root="C:\Program Files\Apache Software Foundation\Tomcat 7.0.59" -Dbitronix.tm.configuration="C:\Program Files\Apache Software Foundation\Tomcat 7.0.59\conf\btm-config.properties" 

Ora riavvia il tuo server e controlla il registro.

metti risorsa-ref nel tag description in web.xml