• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need Help while running stateless session bean with Servelet bean client

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}


}





 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic