[英]What is the best way to make an RDF Model accessible in a JSP view?
I am writing an Java web application that fetches RDF data from URIs and stores them in a Jena Model object. 我正在编写一个Java Web应用程序,该应用程序从URI获取RDF数据并将其存储在Jena Model对象中。 Currently the models contain ordinary triples, some Blank Nodes, no inference.
当前,模型包含普通三元组,一些空白节点,没有推断。 (That is described here already 1 ).
(这里已经描述过1 )。 Using Sesame would be an option, too.
也可以选择使用芝麻。
After data collection, the application displays some of the collected information in a specified order. 数据收集之后,应用程序将以指定的顺序显示一些收集的信息。 It would be necessary to build filters on the model using predicates only and filters specifiying subject & predicate (as we will collect data from several sources);
有必要仅使用谓词在模型上构建过滤器,并指定主题和谓词的过滤器(因为我们将从多个来源收集数据); in each case, the object-literal or URI would be displayed.
在每种情况下,都会显示对象文字或URI。
What would be the best way to generically access the model's contents from a JSP-View (without writing custom tags for each function)? 从JSP-View通用访问模型内容的最佳方法是什么(不为每个函数编写自定义标签)?
The JSP-View would look like this: JSP视图将如下所示:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head></head>
<body>
<img src="${modelBean.model.depictionPred}"/>
Name: <c:out value="${modelBean.model.namePred}"/><br/>
Life dates: <c:out value="${modelBean.model.birthPred}"/>-<c:out value="${modelBean.model.deathPred}"/><br/>
Links: <a href="${modelBean.model.linkPred}">Linktext</a><br/>
...
</body>
</html>
Jena-Servlet to collect data: Jena-Servlet收集数据:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ModelBean modelBean = new ModelBean();
Model model = ModelFactory.createDefaultModel();
model.read("http://dbpedia.org/resource/Ludwig_van_Beethoven");
modelBean.setModel(model);
request.setAttribute("modelBean", modelBean);
RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
rd.forward(request, response);
}
Sesame-Variant of the Servlet: Servlet的Sesame-Variant:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ModelBean modelBean = new ModelBean();
URL url = new URL("http://dbpedia.org/resource/Ludwig_van_Beethoven");
URLConnection conn = url.openConnection();
conn.addRequestProperty("Accept", RDFFormat.TURTLE.getDefaultMIMEType());
InputStream is = conn.getInputStream();
try {
Model model = Rio.parse(is, url.toString(), RDFFormat.forMIMEType(conn.getContentType()));
} catch (RDFParseException ex) {
Logger.getLogger(ModelViewTester.class.getName()).log(Level.SEVERE, null, ex);
}
finally {
is.close();
}
modelBean.setModel(model);
request.setAttribute("modelBean", modelBean);
RequestDispatcher rd = request.getRequestDispatcher("/view.jsp");
rd.forward(request, response);
}
Apart from the fact that something may be possible by providing parameters to calls on bean methods (see How to call parameterized method from JSP using JSTL/EL ) I'm afraid you'll have to either create custom tags, or you need to rethink your access strategy. 除了可以通过为bean方法的调用提供参数来实现某些事情(请参阅如何使用JSTL / EL从JSP调用参数化方法 )之外,我担心您还必须创建自定义标签,或者需要重新考虑您的访问策略。
For example, rather than putting the entire RDF Model
into your response, you could do the extraction of relevant data at the servlet-side, and just put the relevant properties that you want to display in your view response, as separate bean properties. 例如,您可以在servlet端提取相关数据,而不是将整个RDF
Model
放入响应中,而只是将要显示在视图响应中的相关属性作为单独的bean属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.