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 开发者_如何学JAVAresponse 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();
}
}
}
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
精彩评论