异常转发 Jena ResultSet
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 HttpServletResponse 的 Javadoc 中会出现你想调用response.getOutputStream()来获取要写入的实际HTTP响应流而不是使用System.out
然后你可能还想使用ResultSetFormatter 的不同重载 < code>out() 或
output()
方法,以便更好地控制结果格式,例如希望这有帮助
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 usingSystem.out
Then you also may want to be using a different overload of the ResultSetFormatter
out()
oroutput()
method in order to have more control over the results format e.g.Hope this helps