Discussion:
Servlet client unable to access SessionBean method
(too old to reply)
Beatriz Campo González
2005-02-16 15:45:07 UTC
Permalink
Hello,
I've deployed a simple SessionBean with jndi name="Libro"
I've written a servlet, the client of the EJB, which tries to access to "saluda()", the method of the EJB. I get the following error when I compile the client:

cannot find symbol
symbol: variable sal
location: myServlet
sal.saluda();

Here is the code for the servlet:

res.setContentType("text/html");
PrintWriter out = res.getWriter();

out.println("");
out.println("");
out.println("");

try
{
Context contexto = new InitialContext();
Object ref = contexto.lookup("Libro");
LibroHome home =
(LibroHome) PortableRemoteObject.narrow(ref,Beans.LibroHome.class);
Libro sal = home.create();
}

catch (Exception e)
{
e.printStackTrace();
}


sal.saluda();//<---------HERE IS THE ERROR
out.println("");
out.close();

The "saluda()" method only prints a greeting, it's quite simple.

I don't know what is wrong? maybe the package?? I'm really confused

Any help will be welcome?:|
Rob Woollen
2005-02-16 18:32:02 UTC
Permalink
try blocks define scopes in java.

so:

try {
String foo = "Rob":
} catch () ...

foo = "me";

will give you a compilation error.


Either

String foo = "Rob";

try {
foo = "me";
} catch () ...

foo = "you";

is correct:

or

try {
String foo = "Rob";
foo = "you";
} catch ()...

-- Rob
Post by Beatriz Campo González
Hello,
I've deployed a simple SessionBean with jndi name="Libro"
cannot find symbol
symbol: variable sal
location: myServlet
sal.saluda();
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("");
out.println("");
out.println("");
try
{
Context contexto = new InitialContext();
Object ref = contexto.lookup("Libro");
LibroHome home =
(LibroHome) PortableRemoteObject.narrow(ref,Beans.LibroHome.class);
Libro sal = home.create();
}
catch (Exception e)
{
e.printStackTrace();
}
sal.saluda();//<---------HERE IS THE ERROR
out.println("");
out.close();
The "saluda()" method only prints a greeting, it's quite simple.
I don't know what is wrong? maybe the package?? I'm really confused
Any help will be welcome?:|
Loading...