Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding Wikipedia query forms in java using jena
    primarykey
    data
    text
    <pre><code>#!/usr/local/bin/python import sys sys.path.append('/usr/home/bobd/lib/python/') # needed for hosted version from SPARQLWrapper import SPARQLWrapper, JSON import string import urllib import cgi def main(): form = cgi.FieldStorage() dir1name = form.getvalue('dir1') dir2name = form.getvalue('dir2') sparql = SPARQLWrapper("http://data.linkedmdb.org/sparql") queryString = """ PREFIX m: &lt;http://data.linkedmdb.org/resource/movie/&gt; SELECT DISTINCT ?actorName WHERE { ?dir1 m:director_name "DIR1-NAME". ?dir2 m:director_name "DIR2-NAME". ?dir1film m:director ?dir1; m:actor ?actor. ?dir2film m:director ?dir2; m:actor ?actor. ?actor m:actor_name ?actorName. } """ queryString = queryString.replace("DIR1-NAME",dir1name) queryString = queryString.replace("DIR2-NAME",dir2name) sparql.setQuery(queryString) sparql.setReturnFormat(JSON) try: ret = sparql.query() results = ret.convert() requestGood = True except Exception, e: results = str(e) requestGood = False print """Content-type: text/html &lt;html&gt; &lt;head&gt; &lt;title&gt;results&lt;/title&gt; &lt;link href="simple.css" type="text/css" rel="stylesheet" /&gt; &lt;/head&gt; &lt;body&gt; """ if requestGood == False: print "&lt;h1&gt;Problem communicating with the server&lt;/h1&gt;" print "&lt;p&gt;" + results + "&lt;/p&gt;" elif (len(results["results"]["bindings"]) == 0): print "&lt;p&gt;No results found.&lt;/p&gt;" else: for result in results["results"]["bindings"]: print "&lt;p&gt;" + result["actorName"]["value"] + "&lt;/p&gt;" print "&lt;/body&gt;&lt;/html&gt;" main() </code></pre> <p>i got the above code from <a href="http://www.ibm.com/developerworks/xml/library/x-wikiquery/#download" rel="nofollow">http://www.ibm.com/developerworks/xml/library/x-wikiquery/#download</a> </p> <p>Now,i want to do the same thing in java with servlets instead of cgi script.</p> <p>so,how do i pass the query from servlet to <a href="http://data.linkedmdb.org/sparql" rel="nofollow">http://data.linkedmdb.org/sparql</a> endpoint using jena ?</p> <p>and how should i get the result back and display it in a html form ?</p> <p>PLease,HELP</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload