• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet - RMI Error

 
Varun Rupela
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
I wrote a simple application that uses RMI and got it to work. The application involves a client that invokes a remote method (on the server) for adding 2 numbers and returns the sum to the client.
When I tried to use a Servlet as a client of the remote method I get the following exception:
"error unmarshalling return; nested exception is: java.lang.ClassNotFoundException: impl_Stub ""
impl_Stub is the name of the Stub that "rmic" generated from the interface implementation.
It would be great if someone could help me correct the error.
In order to use RMI along with Servlets do I need to things in a different manner?
Question 2:
Just for kicks: In a Servlet, I tried to (use the response Writer to) print the value of a static varible from another class. There were no compilation errors. But when accessing the servlet from the internet, the web page showed an "Internal Server Error"?
Do I need to use the RequestDispatcher?
Thank you.
Varun.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Sure sounds like the servlet client is unable to find the stub code. You did put the class in a package didn't you? And put the class file under WEB-INF/classes where the servlet will look. There is nothing magic about using RMI with servlets, you just have to obey the rules for classes that servlets use.
2. There is no reason that should not work. You did put a try/catch in your doGet or doPost, right? If not, look at the servlet engine logs.
Bill
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13064
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varun - you sent me a private message but I cant reply due to your private message settings. Therefore I will repeat the basic msg.

Could you direct me to a resource that lists the rules to be followed while using RMI in Servlets? My Servlet is still not working and I am guessing I might have missed some things out.

I actually have an example in my Servlets and JSP book. My suggestion is that you do what I did and experiment with RMI outside the servlet environment until you are sure that part is working.
In the servlet environment you mainly have to ensure that:
1. all your code is in a package
2. your compiled client class files are in WEB-INF where the servlet engine can find them.
Bill
 
Varun Rupela
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you again Mr. Brogden:
I will try and follow your instructions and let you know what happens.
Thank you.
Varun.
 
Varun Rupela
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Mr. Brogden:
I have been able to use RMI such that all my code is in packages and it works correctly.
Now, when I am going to be using a servlet as a client:
1. Should the Servlet be in a package as well?
2. Is WEB-INF a file or a directory? I guess it is a file that the Servlet engine checks to know which class files to load?
3. Which "compiled class files" do I place in WEB-INF? - (Do I place the class file of the interface and the stub in it)?
I appreciate your being patient with me.
Thank you.
Varun.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic