Discussions

EJB programming & troubleshooting: Could i use an EJB as a controller just like we use servlet in M

  1. HI!
    I have following senario

    Swing client (send/receive java object)-----Internet/JNDI----Controller at server(send/ receive java object)

    Now since i have to send and receive java objects on client and server end so should i use a stateless session bean to act as a controller and allow my swing client to access that ejb controller's remote interface(through JNDI) and send receive java object through it or is there anyother good approach to do that...

    NOTE:-
    I have been trying to do that senario using servlet on server end...You can found discussion abut taht topic on following link
    http://forum.java.sun.com/thread.jspa?threadID=627481&tstart=0
    but i have found that i cann't send/receive jaav object at client/servlet end .....
  2. Yes but..[ Go to top ]

    You appear to be programming quite alot beyond your skills; this is not necessarily a bad thing but you might find things easier if you did some reading on this area.

    There is a whole spectrum of ways to sent objects, you should probably look for some tutorials:
    Java RMI comes built in to the JRE
    yes EJB can do this (normally using RMI), but unless you need EJB for another reason it is overkill.
    JMS - again I doubt you need this.
    add finally you can use servlets directly for this:

    1) you were misinformed: it is entirely possilble to send any type of data you want to and from a servlet, including serialized objects, BUT you will have to handle it yourself.
    eg use java's ObjectOutputStream and ObjectInputStream and for safety set the content type to that for a serialized java object.

    2) connectivity issues - from the sun forum - note if you use method POST you can send data from the client in the body and the request will be sent to the doPost servlet method. if you use method GET you can't send data in the body and the servlet method doGet will be called. This is basic HTTP standard stuff. The 405 errors you were getting where because you invoked POST when you had no doPost method. and the connection refused error was probably because you forgot to specify the port in the URL (if no post is specified it will defualt to 80, you probably want 8080).. basic TCP stuff.

    3) Is the swing app the only way the service will be accessed. If not then you may want to use more HTTP native ways to send that data than serialized objects such as URL encoding the data so the same endpoint can be used both for a HTML form and the client.