Hello, Friends
I don't know how to solve this. I wrote a simple Jena web application in
order to query on a simple LOM RDF file. I am using a MVC model, so that the
control view is composed by servlets. Excuse me for the long post...but here
is the code snippet:
{..............}
String filename = "/WEB-INF/TesteLOM2.rdf";
ServletContext context = getServletContext();
InputStream in = context.getResourceAsStream(filename);
if (in != null) {
Model model = ModelFactory.createMemModelMaker()
.createDefaultModel();
model.read(in, null);
// null base URI, since model URIs are absolute
in.close();
@SuppressWarnings("unchecked")
List<String> lista = (List<String>) request.getSession()
.getAttribute("sugestao");
String palavrachave = null;
for (Iterator<String> iter = lista.iterator(); iter.hasNext();)
{
palavrachave = iter.next();
// Creates a query....
String queryString =
"PREFIX NS1:<http://www.exemplo.com/#> "
+ "PREFIX rdf:<
http://www.w3.org/1999/02/22-rdf-syntax-ns#>"
+ "PREFIX dcterms:<http://purl.org/dc/terms/>"
+ "PREFIX dc:<http://purl.org/dc/elements/1.1/>"
+ "PREFIX lom:<
http://ltsc.ieee.org/rdf/lomv1p0/terms/> "
+ "PREFIX lomvoc:<
http://ltsc.ieee.org/rdf/lomv1p0/vocabulary#>"
+ "SELECT ?title ?LearningResourceType ?location "
+ "WHERE {"
+ " ?keyword lom:keyword \""
+ palavrachave
+ "\""
+ " ."
+ " ?keyword dc:title ?title ."
+ " ?keyword lom:location ?location ."
+ " ?keyword lomvoc:LearningResourceType
?LearningResourceType."
+ "}";
Query query = QueryFactory.create(queryString);
// get the results...
QueryExecution qe = QueryExecutionFactory.create(query,
model);
ResultSet results = qe.execSelect();
request.getSession().setAttribute("results", results);
// Just for debugging....
ResultSetFormatter.out(System.out, results, query);
qe.close();
}
request.getAttribute("results");
request.getRequestDispatcher(VIEW).forward(request, response);
VIEW is a JSP to render the results:
{...........}
<form method="post" action="ControlaBuscaDeObjetos">
<fieldset>
<legend> Objetos Selecionados </legend>
<p> some explanation...</p>
<table>
<c:forEach items="${results}" var="item">
<tr>
<td>${item}</td>
</tr>
</c:forEach>
</table>
</fieldset>
</form>
++++++++++++++++++++++++
The terminal output is OK:
-------------------------------------------------------------------------
| title | LearningResourceType | location |
=========================================================================
| "Força Resultante" | "narrativetext" | "file:///path" |
| "Calculo da Força Resultante" | "Problem Statement" | "file:///path" |
-------------------------------------------------------------------------
------------------------------------------------------------
| title | LearningResourceType | location |
============================================================
| "Momento Linear" | "Problem Statement" | "file:///path" |
------------------------------------------------------------
-------------------------------------------------------------------------------
| title | LearningResourceType |
location |
===============================================================================
| "Velocidade" | "narrativetext" |
"file:///path" |
| "Velocidade no Movimento Harmônico" | "Problem Statement" |
"file:///path" |
| "Velocidade " | "Problem Statement" |
"file:///path" |
-------------------------------------------------------------------------------
------------------------------------------------------
| title | LearningResourceType | location |
======================================================
| "Derivada" | "narrativetext" | "file:///path" |
------------------------------------------------------
-------------------------------------------------------------
| title | LearningResourceType | location |
=============================================================
| "Função Contínua" | "narrativetext" | "file:///path" |
-------------------------------------------------------------
-------------------------------------------------------
| title | LearningResourceType | location |
=======================================================
| "Sequência" | "narrativetext" | "file:///path" |
-------------------------------------------------------
++++++++++++++++++++++++++++++++++++++
But I can't get it rendered at JSP. What am I doing wrong?
--
Herli Menezes
*Per Astra ad aspera.*