How to fix a javax.naming.NamingException: Lookup failed

烂漫一生 提交于 2019-12-05 13:15:30

In AddAdmin servlet you have declared

private AdminManager adminManager;

as instance variable. And in init() method you are declaring local variable again with same name that's creating problem

Change

AdminManager adminManager = (AdminManager)context.lookup("java:global/jee-projet-web");  

To

adminManager = (AdminManager)context.lookup("java:global/jee-projet-web");  

Now, this line assigns the value to adminManager

Root cause is

java.lang.NullPointerException
at servlet.add.AddAdmin.doPost(AddAdmin.java:55)  

I guess line number 55 is

adminManager.addAdmin(a);   //variable adminManager is not initialized 

adminManager is null so, calling any method on null throws NPE


Update

Root exception is javax.naming.NameNotFoundException: jee-projet-web not found

This exception is thrown when a component of the name cannot be resolved because it is not bound.

Please ensure that the name jee-projet-web is already bound.

I guess it is typo mistake missing c in jee-projet-web. It should be jee-project-web.

One of possibilities could be that you missed to register Yours bean in ejb-jar.xml or in glassfish-ejb.xml (names of *.xml files may vary)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!