0

I know that similar questions have been asked before, but I would like to know if you can actually call a Servlet to do some work made on an EJB module, and then return the data to the standalone Java GUI application.

The requirement of the project says that both a standalone Java GUI client application, and a web client application should access a Servet to do their work, that is update and retrieve data from a database.

Does it make sense to use servlet for the GUI client to access the EJB, or why not access the EJB directly from the stand alone GUI application without invoking the Servlet at all.

Application Design

1 Answer 1

2

Yes, you could call a servlet which in turn calls an EJB.

But you can call an EJB directly from a stand-alone application as well. If your servlet returns HTML markup (content type "text/html" - for human beings), you will have to parse it (requires effort) to get the same result. Every time the markup changes, your client has to be changed as well.

Even if there is a firewall in between (= direct RMI is not possible), you can use "RMI over http(s)", and there is a HTTP based naming service as well (JBoss offers this functionality).

On the other hand, if you mean a servlet which implements a web service which returns XML or JSON, it's a valid approach, especially if clients from other languages (C++ for example) are involved. Another advantage is that you can read the result using a browser (no need for a special RMI client). In that case have a look at available tutorials to implement a webservice in Java

Sign up to request clarification or add additional context in comments.

4 Comments

What I need is database data to be fetched from the GUI application, and update database data, mostly strings. But the same servlet will be used to serve a web client and return html. I am to struggling to figure out what they mean in the requirement.
The architecture (your chart) does not define it. The web tier could be a servlet and a web service. I cannot tell what their intention is, but from a technical point of view it does not make sense to use one servlet for both clients.
I see it makes sense. But in general, is this something that happens, I mean for a standalone application to access a EJB session facade through a servlet, or they normally access the EJB tier directly. –
There might be reasons; otherwise what is the additional servlet layer good for? So yes, access EJBs directly - it should be faster and simpler.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.