Re: Servlet To Java Application Communication
From: Anast (anastasiosm_at_hotmail.com)
Date: 04/13/04
- Previous message: David Harper: "Re: long order_id = ((org.gjt.mm.mysql.PreparedStatement)statement).getLastInsertID();"
- In reply to: Silvio Bierman: "Re: Servlet To Java Application Communication"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 13 Apr 2004 14:41:49 -0700
"Silvio Bierman" <sbierman@idfix.nl> wrote in message news:<407bf09b$0$560$e4fe514c@news.xs4all.nl>...
> "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
I'm glad to hear that there is nothing unusual about what I'm planning
to do:) I ll try your structure.
Thank you very much Silvio.
- Previous message: David Harper: "Re: long order_id = ((org.gjt.mm.mysql.PreparedStatement)statement).getLastInsertID();"
- In reply to: Silvio Bierman: "Re: Servlet To Java Application Communication"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|