views:

39

answers:

3

I have a database from which I want to expose data.

Ideally I would like to be able to just add a URL into some other web page and that URL would then call the correct datum using the web app I use to interact with the database.

Would a web service be the best option?

+3  A: 

Looks to me like a perfect job for ODATA:

The Open Data Protocol (OData) is a Web protocol for querying and updating data that provides a way to unlock your data and free it from silos that exist in applications today. OData does this by applying and building upon Web technologies such as HTTP, Atom Publishing Protocol (AtomPub) and JSON to provide access to information from a variety of applications, services, and stores.

See it action (showing query results in a browser is just one way to use ODATA).

Andreas_D
The need to be tied towards AtomPub is a little annoying. Personally I prefer using RDF so I might have to do something similar but a custom version.
Ankur
A: 

The approach here depends on whether you are doing Ajax style web pages or simple HTML, where each UI update refreshes the whole page.

The latter, a traditional page by page web site, it probably the simplest thing. For this explore JSP technologies. The idea is that you write what looks like an HTML page, but embed in it references to Java objects (or even Java code). In this case you should read up on simple frameworks such as Struts. The broad-brish idea is that you get this sequence of processing

 Request arrives from Broswer, interpret it to figure out what the user wants to see
 Some Java code talks to the Database gets data puts it in a Java Object
 A JSP is chosen, that JSP picks items from the Java Object we just prepared
 The JSP renders HTML which is sent to the Browser

In the case of Ajax, JavaScript in the Browser decides to display some data and calls a service to get it. So here, yes a "Web Service" of some kind is needed. Usually we use REST services, which return a payload in JSON format, effectively the data is transferred as JavaScript.

There are plenty of libraries for creating RESTful Web Services, for example Apache Wink.

djna
Thanks although I think this is a little "heavy weight" for my needs. I can program web apps, the idea is anyone making a web page should be able to grab the data easily.
Ankur
+1  A: 

A URL-based solution as you describe would only work if:

a) the web app framework you use can resolve the URL automatically as it parses and sends the HTML to the browser, or

b) the browser resolves the URL (e.g. the IMG element)

If the web app framework you use can resolve the URL (or if you can extend it so that it does), then you still need something that listens at that URL and retrieve the correct element from the database.

Joubert Nel
Thanks useful ideas.
Ankur