异常转发Jena ResultSet

时间:2011-09-11 20:16:15

标签: jsp servlets path rdf

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();

        }

    }
}

1 个答案:

答案 0 :(得分:0)

HttpServletResponse的Javadoc看来,您希望调用response.getOutputStream()来获取要写入的实际HTTP响应流而不是使用System.out

然后您还可能希望使用ResultSetFormatter out()output()方法的不同重叠,以便更好地控制结果格式,例如

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

希望这有帮助