Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax naming name not found exception jndi in struts2.0

 
Jordan Josh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi to all Ranchers,
I am making connection pool with tomcat.i define necessary entry in server.xml,web.xml and made one listener class to get the connection.but i am getting error "javax naming name not found exception jndi" when i start the tomcat server.and also in my listener value of dataSourcejndi name is displayed null.

Please guide me how to get the jndidatasource name in listener .I attached three files for your reference in single file.
1)web.xml
2)server.xml
3)Applistener.java

web.xml


2)Server.xml(in tomcat)



3)Listener Class to get the jndidatasource name
i am getting the jndiname null
package util;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;

public class AppListener implements ServletContextListener {
public void contextInitialized(ServletContextEvent sce) {

ServletContext servletContext = sce.getServletContext();
String dataSourceJndiName = servletContext.getInitParameter
("dataSourceJndiName");
System.out.println("jndiname-->"+dataSourceJndiName);
try{
Context context = new InitialContext();
DataSource dataSource = (DataSource)context.lookup
("dataSourceJndiName");

servletContext.setAttribute("dataSource",dataSource);
}catch(Exception e)
{
e.printStackTrace();
}
}
public void contextDestroyed(ServletContextEvent des) {

}

}


Thank you in advance
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should ask in a JNDI/Tomcat-oriented forum; this has nothing to do with Struts.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic