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 Certification (SCBCD/OCPJBCD) and the fly likes Need Help  while running  stateless session bean with Servelet bean client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Need Help  while running  stateless session bean with Servelet bean client" Watch "Need Help  while running  stateless session bean with Servelet bean client" New topic
Author

Need Help while running stateless session bean with Servelet bean client

rachna jain
Ranch Hand

Joined: Jul 14, 2009
Posts: 74
Hi All

I have made one EJB project and one Dynamic web project in eclipse IDE on JBOSS.

I have run stateless sesison bean code with normal java class client.

But now i am using servelet as a client.

Please let me know what i am missing as after i deployed project having bean and run servelet on server it says can not find servelet

Stateless bean
package ejb3inaction.example.buslogic;

import javax.ejb.Stateless;
import ejb3inaction.example.persistence.Bid;
/**
* Session Bean implementation class PlaceBidBean
*/
@Stateless
public class PlaceBidBean implements PlaceBidBeanLocal {

/**
* Default constructor.
*/
public PlaceBidBean() {
// TODO Auto-generated constructor stub
}

@Override
public Bid addBid(Bid bid) {
// TODO Auto-generated method stub
System.out.println("Adding bid, bidder ID=" +
bid.getBidderID()
+ ", item ID=" + bid.getItemID() + ","
+ ", bid amount=" + bid.getBidAmount() + ".");


return save(bid);

}

private Bid save(Bid bid) {
// TODO Auto-generated method stub
return null;
}



}



LOCAL INTERFACE

package ejb3inaction.example.buslogic;
import javax.ejb.Local;
import ejb3inaction.example.persistence.Bid;
@Local
public interface PlaceBidBeanLocal {
Bid addBid(Bid bid);
}




SERVELET

package ejb3inaction.example.buslogic;

import java.io.IOException;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ejb3inaction.example.persistence.Bid;

/**
* Servlet implementation class PlaceBidServlet
*/
public class PlaceBidServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public PlaceBidServlet() {
super();
// TODO Auto-generated constructor stub
}

@EJB
private PlaceBidBeanLocal placeBid;

/**
* @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
*/
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
// TODO Auto-generated method stub

int bidderID = 2;
int itemID = 1;

double bidAmount = 100;

Bid bid = new Bid();
bid.setBidderID(bidderID);
bid.setItemID(itemID);
bid.setBidAmount(bidAmount);

placeBid.addBid(bid);
}



}



BID CLASS

package ejb3inaction.example.persistence;




public class Bid {

private int bidderID;
private int itemID;
private double bidAmount;



public int getBidderID() {
return bidderID;
}
public void setBidderID(int bidderID) {
this.bidderID = bidderID;
}
public int getItemID() {
return itemID;
}
public void setItemID(int itemID) {
this.itemID = itemID;
}
public double getBidAmount() {
return bidAmount;
}
public void setBidAmount(double bidAmount) {
this.bidAmount = bidAmount;
}


}






Rachna Jain

SCWCD 1.5
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Unless you are using servlet 3 and the @WebServlet annotation, you need to use the web.xml deployment descriptor to define the servlet.
See example at this web page: http://wiki.metawerx.net/wiki/Web.xml
Note that the above example page contains a lot of things you do not need. Just look at the servlet section!
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need Help while running stateless session bean with Servelet bean client
 
Similar Threads
Facing problem running simple ejb 3.0 example using eclipse and jboss
A session bean class must not have a superclass that is itself a session bean class.
Dependency injection using Ejb3 in jboss-5.0.1.GA (and jdk 5)
CascadeType.PERSIST not working
please help ..... error while running program using eclipse