javax.naming.NameNotFoundException: SessionEJBBean not found

Please help I am getting error: javax.naming.NameNotFoundException: SessionEJBBean not found.

I am using JDeveloper 10g as editor.

The embedded server is running, SessionEJBBean is also there. I have restarted the computer, changed 'SessionEJB' from 'SessionEJBBean'. Yet No success. This is what I get.:

javax.naming.NameNotFoundException: SessionEJBBean not found

at com.evermind.server.rmi.RMIClientContext.lookup(RMIClientContext.java:52)

at javax.naming.InitialContext.lookup(InitialContext.java:351)

at friends.SessionEJBClient.main(SessionEJBClient.java:11)

Process exited with exit code 0.

SessionEJBClient.java

--

package friends;

import javax.naming.Context;

import javax.naming.InitialContext;

import javax.naming.NamingException;

publicclass SessionEJBClient{

publicstaticvoid main(String [] args){

try{

final Context context = getInitialContext();

SessionEJB sessionEJB = (SessionEJB)context.lookup("SessionEJBBean");

}catch (Exception ex){

ex.printStackTrace();

}

}

privatestatic Context getInitialContext()throws NamingException{

// Get InitialContext for Embedded OC4J

// The embedded server must be running for lookups to succeed.

returnnew InitialContext();

}

}

Thank you.

[2296 byte] By [anurag_patila] at [2007-11-27 1:36:57]
# 1

1) you should look up the bean Home using JNDI, not the actual bean

2) JNDI looks up the EJB using the name "SessionEJBBean" that you gave it.

If you didn't specify the same name in your deployment descriptor so that it will be bound to the actual EJB, there is no way JNDI will find the bean?

It would be a good idea to go through a tutorial at this point. Search for Sun's J2EE tutorial and read the EJB application client section.

karma-9a at 2007-7-12 0:47:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 2

Thanks Karma-9 for your reply. My issue has got resolved as I followed this link:

http://www.oracle.com/technology/obe/obe1013jdev/10131/10131_ejb_30/ejb_30.htm

However I have now new problem in hand, when I am trying to insert data in database

using JSP. I am having problem with request.getParameter(). It is not

recognised by JSP. A red underline is being shown below

request.getParameter(). One more thing, in JSP page, if I take cursor over

'request' in request.getParameter, it shows, 'Name request not found'. When

I take cursor over 'getParameter' in request.getParameter, it shows, 'Method

getParameter (java.lang.String) not found in<unknown>'.

This is my code:

MyPage.jsp

--

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<%@ page contentType="text/html;charset=windows-1252"%>

<%@ page import="java.sql.*, javax.naming.Context,

javax.naming.InitialContext, javax.naming.NamingException,

friendspackage.*, java.text.*, java.util.*"%>

<%!

public void jspInit () {

String name, city;

name = request.getParameter("name");

city = request.getParameter("city");

try {

final Context context = getInitialContext();

SessionFriends sessionFriends =

(SessionFriends)context.lookup("SessionFriends");

sessionFriends.addFriends("name","city");

//System.out.println( "Success" );

} catch (Exception ex) {

ex.printStackTrace();

}

}

private static Context getInitialContext() throws NamingException {

// Get InitialContext for Embedded OC4J

// The embedded server must be running for lookups to succeed.

return new InitialContext();

}

%>

MyPage.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html;

charset=windows-1252"></meta>

<title>My Friends</title>

</head>

<body>

<form name="MyFriends" action="MyFriends.jsp" method="post">

Name:

<input type="text" name="name">

City:

<input type="text" name="city">

<input type="submit" value="Submit">

</form>

</body>

</html>

Please let me know if I have to make any changes in web.xml which is:

<?xml version = '1.0' encoding = 'windows-1252'?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"

xmlns="http://java.sun.com/xml/ns/j2ee">

<description>Empty web.xml file for Web Application</description>

<session-config>

<session-timeout>35</session-timeout>

</session-config>

<mime-mapping>

<extension>html</extension>

<mime-type>text/html</mime-type>

</mime-mapping>

<mime-mapping>

<extension>txt</extension>

<mime-type>text/plain</mime-type>

</mime-mapping>

</web-app>

Thank you again.

Anurag

anurag_patila at 2007-7-12 0:47:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 3
That's probably because your program can't find the servlet.jar (where is it?), so it doesn't recognize nor the JSP request implicit object, nor the servlet API method.
karma-9a at 2007-7-12 0:47:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 4
Hi Karma,Thank you for reply. I have found servlet.jar file in D:\soft\jdevstudio10132\j2ee\home\lib. What to do next? Thanks again.Anurag
anurag_patila at 2007-7-12 0:47:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 5
You have to include it in your JDeveloper project. I'm not familiar with JDeveloper, so I can't be of further help.
karma-9a at 2007-7-12 0:47:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...
# 6

My Issue is resolved as changed JSP file as:

<%@ page language="java" contentType="text/html" %>

<%@ page import="java.sql.*, javax.naming.Context,

javax.naming.InitialContext, javax.naming.NamingException,

friendspackage.*, java.text.*, java.util.*"%>

<%@ page import="javax.servlet.RequestDispatcher,

javax.servlet.ServletConfig, javax.servlet.ServletException,

javax.servlet.http.HttpServlet, javax.servlet.http.HttpServletRequest,

javax.servlet.http.HttpServletResponse, javax.servlet.http.HttpSession"%>

<%!

private SessionFriends sessionFriends = null;

public void jspInit () {

try {

InitialContext ctx = new InitialContext();

sessionFriends = (SessionFriends) ctx.lookup(

"SessionFriends");

} catch (Exception e) {

e.printStackTrace ();

}

}

%>

<%

String name, city;

name = request.getParameter("name");

city = request.getParameter("city");

sessionFriends.addFriends(name,city);

%>

Thank you.

anurag_patila at 2007-7-12 0:47:00 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...