File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Servlet calling EJB - compiling problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Servlet calling EJB - compiling problems" Watch "Servlet calling EJB - compiling problems" New topic
Author

Servlet calling EJB - compiling problems

Sagar Sharma
Ranch Hand

Joined: Aug 31, 2000
Posts: 92
Hi,
I have written the following servlet to havdle an HTTP request and get a parameter. The parameter is then passed to an Entity Bean which calls upon the database. The ResultSet object is the returned to the Servlet for displaying the results in a tabular form.
i am getting very basic errors while compiling saying that "PortSearchHome" & "PortSearchObject" classes are not found.
I have already compiled these interfaces and they exist in the same directory from which I am trying to compile the servlet i.e. d:\jdk1.2.1\bin
****THE CODE****
import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import javax.sql.*;
import javax.ejb.*;
import javax.rmi.*;
import javax.naming.*;
import java.sql.*;

public class PortSearchServlet extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
String title="Port Search by Country";
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("<HTML><HEAD><TITLE>title</TITLE></HEAD>");
String country=request.getParameter("COUNTRY");
if (country!=null){
String s=request.getParameter("Country_Selected");
ResultSet rs=getResult(s);
try{
while(rs.next()){
String port_name=rs.getString("PORT_NAME");
out.println("<BODY BGCOLOR=\"#FDF5E6\">\n"+"<H1 ALIGN=CENTER>"+title+"</H1>\n"+"\n"+"\n"+""); } }catch(java.sql.SQLException sqle){ System.out.println("SQL EXCEPTION CAUGHT " + sqle); } out.println("
Parameter Value"); out.println("
port_name
");
}
out.println("</BODY></HTML>");
out.close();
}

public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
doGet(request,response);
}
public ResultSet getResult(String s){
try{
javax.naming.Context context=new javax.naming.InitialContext();
Object ref=context.lookup("PortSearch");
PortSearchHome home=(PortSearchHome) javax.rmi.PortableRemoteObject.narrow(ref,PortSearchHome.class);
PortSearchObject pso=home.create();
ResultSet rs=pso.getRecords(s);
return rs;
}catch(NamingException ne){
System.out.println("Naming Exception caught " + ne);
return null;
}
}
}

Have I missed out on some import statements ? or is it something else? Please do help me out.
Also please tell me if there is anything other than this wrong with my code.
Thanks and Regards

Sagar Sharma
Majid Khan
Ranch Hand

Joined: Oct 02, 2000
Posts: 92
Hi Sagar,
I to faced a similar problem whilst compling the servlet caling
bean, it give some err about class files not found
I am not to sure but it seem something to with cp problems
or placing the servlet in a particular dir
I am still working on it, will get back
In the meanwhile anyone any suggestions ??

Regards
Majid
Andrew Jahchand
Greenhorn

Joined: Jul 09, 2001
Posts: 7
Hi,
I am trying to run some examples from the Instant Enterprise JavaBeans book.
When I try to execute the examples using a standalone client I do not seem to have a problem.
Problems occur when I try and run ejbs J2EE application client or servlet clients
Using servlets I get the following:
java.lang.NoSuchMethodError: javax.servlet.ServletRequest: method isSecure()Z not found
I manage to compile and deploy but the problem occurs with the jndi I think
Suresh Ramu
Greenhorn

Joined: Jul 11, 2001
Posts: 5
PortSearchObject should be instantiated from the remote interface class.In this case, it should be "PortSearch" and not "PortSearchObject".

import javax.ejb.*;
import java.rmi.RemoteException;
// general Java
import java.util.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.rmi.*;
import org.omg.CORBA.Object;
import javax.rmi.*;
import java.math.*;
Also, typecast like this:
javax.naming.InitialContext ctx = new javax.naming.InitialContext(props);
Object obj = (Object) ctx.lookup("PortSearch"); //JNDI name
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet calling EJB - compiling problems
 
Similar Threads
how to declare....and pass parameters..
servlet is not working properly
Problem:The requested resource (/ShowParameters) is not available
HTTP POST-Method not supported by this URL.
user authentication and dao