Re: Servlet To Java Application Communication
From: Silvio Bierman (sbierman_at_idfix.nl)
Date: 04/13/04
- Next message: Glacial Spain: "Re: Confusion about database updates"
- Previous message: Mark Scott: "Re: Connecting to MySQL on a Linux box from Borland JBuilder Foundation X"
- In reply to: Anast: "Servlet To Java Application Communication"
- Next in thread: Anast: "Re: Servlet To Java Application Communication"
- Reply: Anast: "Re: Servlet To Java Application Communication"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 13 Apr 2004 15:51:42 +0200
"Anast" <anastasiosm@hotmail.com> wrote in message
news:a993bdfe.0404101939.28861f72@posting.google.com...
> Hi all,
>
> Firstly, I would like to write a Java servlet that it will be able to
> connect with a database (mySQL) and search its contents (using JDBC).
> Then, I would like to build a java application (NOT an applet), so
> that it would be able to search for queries the database, and display
> the results. Have you got any working examples that demonstrate the
> previous described functionality or any similar? I have installed
> Tomcat with MySQL Connector/J and MySQL in my box and work fine. Any
> help would be appreciable.
>
> Many thanks in advance.
In spite of other remarks there is nothing unusual or undesirable about what
you are planning to do...
Look at the URL class. It allows you to do a HTTP GET or POST which is the
way to communicate with a servlet. If you plan to do SOAP requests you
probably know you should encode the request XML in the body part of a POST
and expect the response XML in the response content.
Servlet side:
-implement doPost(request,response)
-use request.getInputStream to read the request-body.
-use request.getOutputStream to write the response.
Application(client) side:
URL url = new URL("http://someserver:someport/somepath");
URLConnection con = url.openConnection();
con.setDoOutput(true);
con.setDoInput(true);
con.setUseCaches(false);
OutputStream out = con.getOutputStream();
//use out to write the request
out.close();
InputStream in = con.getInputStream();
//use in to read the response
in.close();
You can use this construct do do ny type of (HTTP or HTTPS) communication.
You can exchange strings, raw bytes, XML or even serialized Java objects
this way. Using SOAP is fine when going cross-app/cross-language, it is
somewhat bloated in other situation but if you want you can support several
protocals off course.
Consider using GZIP encoding if requests/responses tend to get big and you
might want to support narrow bandwidths.
Good luck,
Silvio Bierman
- Next message: Glacial Spain: "Re: Confusion about database updates"
- Previous message: Mark Scott: "Re: Connecting to MySQL on a Linux box from Borland JBuilder Foundation X"
- In reply to: Anast: "Servlet To Java Application Communication"
- Next in thread: Anast: "Re: Servlet To Java Application Communication"
- Reply: Anast: "Re: Servlet To Java Application Communication"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|