| 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
Bartender
Joined: Oct 04, 2006
Posts: 2193
|
|
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
|
 |
 |
|
|
subject: Need Help while running stateless session bean with Servelet bean client
|
|
|