Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q4051 I am trying to create a three tier client/server in which the client (a Java applet in a web page) collects information, creates a SQL string and send this to a Java JDBC application. It works fine locally using appletviewer and localhost. How do I make this application run as a service on the web server?

You are here: irt.org | FAQ | Java | Q4051 [ previous next ]

You will have to develop a server program (your program) that will run on your web server which will accept calls from the client (the applet).

As you are going for 3-tier client server architecture , the middleware i.e. your server program receives a call from client , through the calling mechanism it transmit the relevent query (which is a SQL query in your case). This data is understood by your server program , it takes proper action, (i.e. it may make a database connection and retrieve the information from database) and transfer the result to the calling applet.

Now the Question is how to achieve this:

There are various methods:

1. Socket Programming

The applet can open a socket on the server (web) from where it has come from. You need to have one server program running on your machine which is continuously listening for call from the client at particular port.

The client too can open a socket your web server m/c at the defined port and write the request information to the socket, this information your server program has to accept an take the proper action, return the results to the caller. The returned information is interpreted by the applet and displayed.

2. RMI (Remote Method Invocation)

Your task is little bit made easier, as RMI protocol is built over Sockets, it takes care of Marshalling of the inputs from the client and server. All you have to do is to call a remote method on your remote object (i.e. Your Server Program) pass the information as a parameter (parameter may be object) and receive result as the return parameter (parameter may be object). The rest of the internal working is hidden for you. But the disadvantage of this is only Java Objects can call your remote method.

Just go through some Nice Book, you will get a sample 3-tier client/server program understand it and build your program.

3. CORBA

Have CORBA object running on your m/c, and they can be called from any other implementation of client.

If you want to go for a 2 tier client/server application you can use the direct database driver (in JAVA) made available by various vendors (like Oracle). With these direct classes you can directly make a call to the database server. For this you need to have DSN (Data Source Name) configured for the database server you are calling. These type of applets are called thin applets (or thin clients).

The other issue you have asked is of making this as service on your web server.

You can design a servlet (if this is not familiar go through JSDK java servlet development kit, visit : http://www.javasoft.com/ ) and you can have your RMI or CORBA or SOCKET (Remote Object which is going to server the client applet) object embedded into servlet and now you can define the start and stop of the servlet as a service on the web server. Just check which web server supports the servlets. Or you can put your server program in startup.

©2018 Martin Webb