异常转发 Jena ResultSet

发布于 2024-12-04 04:52:12 字数 1506 浏览 1 评论 0原文

protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {

    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 =

    // ( SPARQL stuff here...}

    Query query = QueryFactory.create(queryString);

    // get the results...

    QueryExecution qe = QueryExecutionFactory.create(query, model);
    ResultSet results = qe.execSelect();
    request.setAttribute("results", results);
    /*
    * Compiler says error is in next line
    * Got this exception: Cannot forward after response has been committed
    * as I tried to forward results to a jsp page...
    */

    request.getRequestDispatcher(VIEW).forward(request, response);
    // ResultSetFormatter.out(System.out, results, query);
    qe.close();

        }

    }
}
protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {

    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 =

    // ( SPARQL stuff here...}

    Query query = QueryFactory.create(queryString);

    // get the results...

    QueryExecution qe = QueryExecutionFactory.create(query, model);
    ResultSet results = qe.execSelect();
    request.setAttribute("results", results);
    /*
    * Compiler says error is in next line
    * Got this exception: Cannot forward after response has been committed
    * as I tried to forward results to a jsp page...
    */

    request.getRequestDispatcher(VIEW).forward(request, response);
    // ResultSetFormatter.out(System.out, results, query);
    qe.close();

        }

    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2024-12-11 04:52:12

HttpServletResponse 的 Javadoc 中会出现你想调用response.getOutputStream()来获取要写入的实际HTTP响应流而不是使用System.out

然后你可能还想使用ResultSetFormatter 的不同重载 < code>out() 或 output() 方法,以便更好地控制结果格式,例如

ResultSetFormatter.output(response.getOutputStream(), results, ResultSetFormat.syntaxXML)

希望这有帮助

From the Javadoc for HttpServletResponse it would appear you want to be calling response.getOutputStream() to get the actual HTTP response stream to write to rather than using System.out

Then you also may want to be using a different overload of the ResultSetFormatter out() or output() method in order to have more control over the results format e.g.

ResultSetFormatter.output(response.getOutputStream(), results, ResultSetFormat.syntaxXML)

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文