Krzysztof Zielinski
Krzysztof Zielinski

Reputation: 400

Java application uses AJAX


I have to create a desktop client to previously made web application.
Problem is that this application uses ajax to communicate and I have no clue how to communicate with servlet from standalone java app.
Can you give info on how to start ?

Upvotes: 0

Views: 263

Answers (4)

Andrew Fielden
Andrew Fielden

Reputation: 3899

You can establish a HTTP connection to a remote server with a given URL from your desktop client. Here's a small code fragment which demonstrates one way of doing it. The connection uses a session cookie, which may or may not be required in your case.

private void createConnectionToServerWithSessionCookie(String URLStr) throws IOException {
    URL managerURL = new URL(URLStr);
    URLConnection connection = managerURL.openConnection();
    connection.setRequestProperty("Cookie", sessionId);
    connection.connect();
    managerReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
}

Also look here for more information

Upvotes: 1

Snicolas
Snicolas

Reputation: 38168

If you have access to the server part of the application, it would be interesting to consider rebuilding around XML or JSON, better than using HTML and parsing it.

If you don't have access to it, then @Malax is right (+1) and then you should consider using apache jericho for parsing.

Regards, Stéphane

Upvotes: 1

pap
pap

Reputation: 27614

You should take a look at the commons HttpClient library. It's made to be used for programatically making calls to http services.

Upvotes: 3

Malax
Malax

Reputation: 9604

Basically, it's all HTTP. AJAX is just a fancy term to describe asynchronous HTTP calls made from Javascript. Any HTTP Library will aid you to access the data you need, like the Apache HTTPComponents.

Upvotes: 5

Related Questions