Невозможно получить com.hp.hpl.jena.query.ResultSet на страницу Jsp - PullRequest
0 голосов
/ 04 апреля 2011
 import com.hp.hpl.jena.rdf.model.RDFNode;


    public class RowObject {
    private com.hp.hpl.jena.rdf.model.RDFNode name;
    private com.hp.hpl.jena.rdf.model.RDFNode symbol;
    private com.hp.hpl.jena.rdf.model.RDFNode number;
    public void setName(RDFNode name) {
        this.name = name;
    }
    public void setSymbol(RDFNode symbol) {
        this.symbol = symbol;
    }
    public void setNumber(RDFNode number) {
        this.number = number;
    }
public com.hp.hpl.jena.rdf.model.RDFNode getName() {
    return name;
}
public com.hp.hpl.jena.rdf.model.RDFNode getSymbol() {
    return symbol;
}
public com.hp.hpl.jena.rdf.model.RDFNode getNumber() {
    return number;
}

    }

QueryProcessing.java содержит:

com.hp.hpl.jena.query.Query query = QueryFactory.create(queryString);
        QueryExecution qe = QueryExecutionFactory.create(query, model);

        com.hp.hpl.jena.query.ResultSet results = qe.execSelect();

        //ResultSetFormatter.out(System.out, results);
        response.setContentType("text/html");
 List<RowObject> resultss = new ArrayList<RowObject>();

                while ( results.hasNext()) {
                    RowObject result = new RowObject();
                    QuerySolution binding = results.nextSolution();
                    result.setName(binding.get("name"));
                    result.setSymbol(binding.get("symbol"));
                    result.setNumber(binding.get("number"));
                    // ...
                    resultss.add(result);

                }
                request.setAttribute("resultss", resultss); // Will be available as ${results} in JSP
                request.getRequestDispatcher("/Output.jsp").forward(request, response);
    }

output.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri='http://java.sun.com/jsp/jstl/core' prefix='c'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table>
    <c:forEach items="${resultss}" var="rowObject">
        <tr>
        <td>${rowObject.getName()}</td>
        <td>${rowObject.getSymbol()}</td>
        <td>${rowObject.getNumber()}</td>

        </tr>
    </c:forEach>
</table>
</body>
</html>

web.xml начинается с

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Semantic</display-name>

вывод на консоль:

--------------------------------------------------------------------------------------------------------------------------


 | name                                                       | symbol                                           | number |
    ==========================================================================================================================
    | "holmium"^^<http://www.w3.org/2001/XMLSchema#string>       | "Ho"^^<http://www.w3.org/2001/XMLSchema#string>  | 67     |

запрос:

PREFIX table: <http://www.daml.org/2003/01/periodictable/PeriodicTable#>
SELECT ?name ?symbol ?number
FROM <http://www.daml.org/2003/01/periodictable/PeriodicTable.owl>
WHERE
{
  ?element table:name ?name.
  ?element table:symbol ?symbol.
  ?element table:atomicNumber ?number.
}

я выполнил вышеизложенное с помощью Eclipse Ide Существует input.jsp, который передает запроссервлету QueryProcessor, а затем QueryProcessor передает результат в Output.jsp.
Когда я запускаю вышеупомянутое на сервере, я получаю Output на консоли и следующее исключение:

type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

org.apache.jasper.JasperException: /Output.jsp(16,18) The function getName must be used with a prefix when a default namespace is not specified
    org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
...